Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try fixing combobox a11y issues #27431

Merged
merged 3 commits into from
Dec 3, 2020
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions packages/components/src/combobox-control/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ function ComboboxControl( {
const onFocus = () => {
setIsExpanded( true );
onFilterValueChange( '' );
setInputValue( '' );
// setInputValue( '' );

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// setInputValue( '' );

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might as well just remove it instead of commenting out :) We've got git!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops, that was unintended! I don't think removing it changes anything, but it's not needed for the fix so I'll revert the change.

};

const onFocusOutside = () => {
Expand Down Expand Up @@ -170,7 +170,7 @@ function ComboboxControl( {
)
: __( 'No results.' );

speak( message, 'assertive' );
speak( message, 'polite' );
}
}, [ matchingSuggestions, isExpanded ] );

Expand Down Expand Up @@ -203,6 +203,11 @@ function ComboboxControl( {
instanceId={ instanceId }
ref={ inputContainer }
value={ isExpanded ? inputValue : currentLabel }
aria-label={
currentLabel
? `${ currentLabel }, ${ label }`
: null

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any other default value that would be good here rather than null?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The purpose of null here is to not render the aria-label if there's no currently selected value, because in that case, its contents are identical to the already existing label, so we don't need to override it with aria-label.

}
onFocus={ onFocus }
isExpanded={ isExpanded }
selectedSuggestionIndex={ matchingSuggestions.indexOf(
Expand Down