File tree Expand file tree Collapse file tree 1 file changed +15
-8
lines changed Expand file tree Collapse file tree 1 file changed +15
-8
lines changed Original file line number Diff line number Diff line change 11import React , {
2+ useId ,
23 ReactElement ,
34 InputHTMLAttributes ,
45 KeyboardEvent ,
@@ -155,32 +156,37 @@ export const Input = createFC<InputProps, { isFormElement: boolean }>(
155156 prevValueRef . current = e . target . value ;
156157 } ) ;
157158
159+ const prefix = useId ( ) ;
160+
161+ const rawTextId = id ?? `${ prefix } -raw-text-id` ;
162+ const inputId = id ?? `${ prefix } -input-id` ;
163+ const labelForId = readOnly ? rawTextId : inputId ;
164+
165+ const errorId = `${ prefix } -error-id` ;
166+
158167 const { isFieldSetColumn } = useContext ( FieldSetColumnContext ) ;
159168 const inputClassNames = classnames (
160169 className ,
161170 bare ? 'slds-input_bare' : 'slds-input'
162171 ) ;
163172 const inputElem = readOnly ? (
164- < Text
165- id = { id }
166- type = 'regular'
167- category = 'body'
168- className = 'slds-form-element__static'
169- >
173+ < Text id = { rawTextId } type = 'regular' category = 'body' >
170174 { value }
171175 </ Text >
172176 ) : (
173177 < input
174178 ref = { inputRef }
175179 className = { inputClassNames }
176- id = { id }
180+ id = { inputId }
177181 type = { type }
178182 value = { value }
179183 defaultValue = { defaultValue }
180184 readOnly = { htmlReadOnly }
181185 { ...rprops }
182186 onChange = { onChange }
183187 onKeyDown = { onKeyDown }
188+ aria-describedby = { error ? errorId : undefined }
189+ aria-invalid = { error ? true : undefined }
184190 />
185191 ) ;
186192
@@ -206,10 +212,11 @@ export const Input = createFC<InputProps, { isFormElement: boolean }>(
206212 }
207213 if ( isFieldSetColumn || label || required || error || cols ) {
208214 const formElemProps = {
209- id ,
215+ controlId : labelForId ,
210216 label,
211217 required,
212218 error,
219+ errorId,
213220 readOnly,
214221 cols,
215222 tooltip,
You can’t perform that action at this time.
0 commit comments