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

fix: generate elements ids in a consistent manner #1194

Merged
merged 2 commits into from Sep 28, 2023
Merged

Conversation

dhayab
Copy link
Member

@dhayab dhayab commented Sep 26, 2023

Summary

DOM elements within Autocomplete do not follow a consistent naming scheme for their id, which broke one accessibility feature making users unable to always view the active item when navigating using the keyboard arrows.

This PR ensures all elements of Autocomplete have an id that is generated from a single source of truth, making sure they follow a consistent naming scheme.

Also in this PR, some aria- attributes have more meaningful values.

Result

Navigating with the keyboard arrows in an Autocomplete panel always scrolls the active element into view.

FX-2619
Closes #1188

@codesandbox-ci
Copy link

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 10cc1c9:

Sandbox Source
@algolia/autocomplete-example-github-repositories-custom-plugin Configuration
@algolia/autocomplete-example-instantsearch Configuration
@algolia/autocomplete-example-playground Configuration
@algolia/autocomplete-example-preview-panel-in-modal Configuration
@algolia/autocomplete-example-react-renderer Configuration
@algolia/autocomplete-example-starter-algolia Configuration
@algolia/autocomplete-example-starter Configuration
@algolia/autocomplete-example-reshape Configuration
@algolia/autocomplete-example-vue Configuration

Comment on lines +112 to +119
'aria-owns': store.getState().isOpen
? store
.getState()
.collections.map(({ source }) =>
getAutocompleteElementId(props.id, 'list', source)
)
.join(' ')
: undefined,
Copy link
Member Author

@dhayab dhayab Sep 26, 2023

Choose a reason for hiding this comment

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

This is conform to the reference, making Autocomplete the owner of all the sources' lists.

Comment on lines +201 to +208
'aria-controls': store.getState().isOpen
? store
.getState()
.collections.map(({ source }) =>
getAutocompleteElementId(props.id, 'list', source)
)
.join(' ')
: undefined,
Copy link
Member Author

Choose a reason for hiding this comment

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

This gives a comprehensive value of all lists that are controlled by the input (MDN).

? store
.getState()
.collections.map(({ source }) =>
getAutocompleteElementId(props.id, 'list', source)
Copy link
Contributor

Choose a reason for hiding this comment

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

bit unfortunate that this gets calculated again instead of saved in the collection, but it makes sense

Copy link
Member Author

Choose a reason for hiding this comment

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

I didn't create a specific test case for this simple method, because its output is testable on multiple occasions in other integration tests and snapshots.

@dhayab dhayab requested review from a team, sarahdayan and aymeric-giraudet and removed request for a team September 26, 2023 09:44
@dhayab dhayab merged commit a76b914 into next Sep 28, 2023
9 checks passed
@dhayab dhayab deleted the fix/keyboard-navigation branch September 28, 2023 15:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants