feat: expose role prop on Input component for improved accessibility #382
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
📝 Summary
This PR adds support for an optional
roleprop on theInputcomponent. Previously, therolewas hardcoded to"combobox", which limited the component's accessibility (a11y) use cases.🚫 The Problem
The
Inputcomponent is versatile and can be used in various contexts, not just as a combobox. A common use case is as a standalone search bar. For optimal accessibility, a dedicated search input should haverole="search". The hardcoded"combobox"role made this impossible without resorting to non-standard overrides.✅ The Solution
This change modifies the
Inputcomponent to:Accept a new optional
roleprop.Default to
role="combobox"to maintain full backward compatibility for all existing users. The default behavior of the component is unchanged.Pass the prop through to the underlying
<input>element.🧪 Usage Example
Users can now correctly define the role based on their specific context:
As a Combobox (Default, unchanged)
As a Searchbox
♿ Accessibility Impact
This change significantly improves the library's flexibility regarding accessibility. Screen readers and other assistive technologies can now better understand the purpose of the input based on its defined role, leading to a more accurate experience for users.
role="combobox": Correctly indicates the input controls a popup list (the command menu).role="searchbox": Correctly indicates the input is for performing searches, which is a very common use case for this component.🔄 Backwards Compatibility
This change is fully backwards compatible. The
roleprop is optional and defaults to the original value of"combobox". No existing code should break or require modification.