fix(Combobox): add aria attributes on error#2327
fix(Combobox): add aria attributes on error#2327chornonoh-vova wants to merge 1 commit intodevelopfrom
Conversation
- add `aria-invalid` to internal `<input />` when there's an error - add `aria-describedby` to the internal `<Listbox />` Together, these 2 attributes form correct representation of the error state to the screen reader.
There was a problem hiding this comment.
Pull request overview
Updates the Combobox component’s accessibility semantics so assistive technologies can correctly announce error state and associated messaging (notably improving VoiceOver behavior).
Changes:
- Add
aria-invalidto the internal combobox<input>whenerroris present. - Apply the computed
aria-describedbyvalue to the internal<Listbox />as well as the input. - Add tests covering
aria-invalid, listboxaria-describedby, and an additional axe check for error state.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| packages/react/src/components/Combobox/Combobox.tsx | Adds aria-invalid handling and shares computed aria-describedby with the listbox. |
| packages/react/src/components/Combobox/Combobox.test.tsx | Adds unit/behavior tests for the new ARIA attributes and an axe test for error state. |
Comments suppressed due to low confidence (1)
packages/react/src/components/Combobox/Combobox.tsx:746
aria-invalidis set before{...inputProps}, butinputPropsis built from the remainingprops(which can include a consumer-providedaria-invalidsinceBaseComboboxPropsextendsInputHTMLAttributes). Because the spread comes after, a passedaria-invalidwould override the error-driven value, potentially leaving the input not marked invalid even whenerroris rendered. Consider ensuring the component-ownedaria-invalidwins (e.g., move the spread earlier or explicitly strip/overridearia-invalidwhenerroris present).
aria-invalid={error ? true : undefined}
aria-autocomplete={!isAutoComplete ? 'none' : 'list'}
aria-controls={`${id}-listbox`}
aria-expanded={open}
aria-haspopup="listbox"
aria-activedescendant={
open && activeDescendant ? activeDescendant.element.id : undefined
}
{...inputProps}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
This pull request is automatically being deployed by Amplify Hosting (learn more). |
Bracciata
left a comment
There was a problem hiding this comment.
This looks good to me! Claude brought up a concern of consumers overriding props, however, I don't think that is worth us considering.
Summary
aria-invalidto internal<input />when there's an erroraria-describedbyto the internal<Listbox />Together, these 2 attributes form correct representation of the error
state to the screen reader.
When they were missing previously, VoiceOver was not announcing an error
message (even though NVDA did).