Skip to content

Commit aeeaae8

Browse files
(Textarea): improve a11y
1 parent 84094cd commit aeeaae8

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/scripts/Textarea.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React, {
2+
useId,
23
ChangeEvent,
34
ReactNode,
45
Ref,
@@ -56,6 +57,7 @@ export const Textarea = createFC<TextareaProps, { isFormElement: boolean }>(
5657
prevValueRef.current = e.target.value;
5758
});
5859
const { isFieldSetColumn } = useContext(FieldSetColumnContext);
60+
const errorId = useId();
5961
const taClassNames = classnames(className, 'slds-textarea');
6062
const textareaElem = readOnly ? (
6163
<Text type='regular' category='body'>
@@ -68,14 +70,16 @@ export const Textarea = createFC<TextareaProps, { isFormElement: boolean }>(
6870
className={taClassNames}
6971
{...rprops}
7072
onChange={onChange}
73+
aria-describedby={error ? errorId : undefined}
7174
/>
7275
);
7376
if (isFieldSetColumn || label || required || error || cols) {
7477
const formElemProps = {
75-
id,
78+
htmlFor: id,
7679
label,
7780
required,
7881
error,
82+
errorId,
7983
cols,
8084
tooltip,
8185
tooltipIcon,

0 commit comments

Comments
 (0)