11import React , {
2+ useId ,
23 ChangeEvent ,
34 ReactNode ,
45 Ref ,
@@ -7,6 +8,7 @@ import React, {
78 useRef ,
89} from 'react' ;
910import classnames from 'classnames' ;
11+ import { Text } from './Text' ;
1012import { FormElement , FormElementProps } from './FormElement' ;
1113import { FieldSetColumnContext } from './FieldSet' ;
1214import { useEventCallback } from './hooks' ;
@@ -25,6 +27,8 @@ export type TextareaProps = {
2527 elementRef ?: Ref < HTMLDivElement > ;
2628 textareaRef ?: Ref < HTMLTextAreaElement > ;
2729 onValueChange ?: ( value : string , prevValue ?: string ) => void ;
30+ readOnly ?: boolean ;
31+ htmlReadOnly ?: boolean ;
2832} & TextareaHTMLAttributes < HTMLTextAreaElement > ;
2933
3034/**
@@ -45,6 +49,8 @@ export const Textarea = createFC<TextareaProps, { isFormElement: boolean }>(
4549 textareaRef,
4650 onChange : onChange_ ,
4751 onValueChange,
52+ readOnly,
53+ htmlReadOnly,
4854 ...rprops
4955 } = props ;
5056 const prevValueRef = useRef < string > ( ) ;
@@ -54,26 +60,40 @@ export const Textarea = createFC<TextareaProps, { isFormElement: boolean }>(
5460 prevValueRef . current = e . target . value ;
5561 } ) ;
5662 const { isFieldSetColumn } = useContext ( FieldSetColumnContext ) ;
57- const taClassNames = classnames ( className , 'slds-input' ) ;
58- const textareaElem = (
63+ const errorId = useId ( ) ;
64+ const taClassNames = classnames ( className , 'slds-textarea' ) ;
65+ const textareaElem = readOnly ? (
66+ < Text
67+ id = { id }
68+ type = 'regular'
69+ category = 'body'
70+ className = 'slds-form-element__static'
71+ >
72+ { rprops . value }
73+ </ Text >
74+ ) : (
5975 < textarea
6076 id = { id }
6177 ref = { textareaRef }
6278 className = { taClassNames }
79+ readOnly = { htmlReadOnly }
6380 { ...rprops }
6481 onChange = { onChange }
82+ aria-describedby = { error ? errorId : undefined }
6583 />
6684 ) ;
6785 if ( isFieldSetColumn || label || required || error || cols ) {
6886 const formElemProps = {
69- id,
87+ controlId : id ,
7088 label,
7189 required,
7290 error,
91+ errorId,
7392 cols,
7493 tooltip,
7594 tooltipIcon,
7695 elementRef,
96+ readOnly,
7797 } ;
7898 return < FormElement { ...formElemProps } > { textareaElem } </ FormElement > ;
7999 }
0 commit comments