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 autocomplete keyboard control on Windows/Edge #170

Merged
merged 5 commits into from
Jun 27, 2024

Conversation

kochis
Copy link
Collaborator

@kochis kochis commented Jun 13, 2024

The main fix is to change from event.code to event.key for handling keyboard events, which was breaking on Windows/Edge.

Other enhancements are additional aria-roles for accessibility.

@kochis kochis changed the title WIP: add more aria role support for autocomplete widget Fix autocomplete keyboard control on Windows/Edge Jun 26, 2024
Copy link
Contributor

@jaspk06 jaspk06 left a comment

Choose a reason for hiding this comment

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

is there a tldr on the aria attributes we added?

@@ -136,6 +132,10 @@ class AutocompleteUI {
// result list element
this.resultsList = document.createElement('ul');
this.resultsList.classList.add(CLASSNAMES.RESULTS_LIST);
this.resultsList.classList.add('id', CLASSNAMES.RESULTS_LIST);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
this.resultsList.classList.add('id', CLASSNAMES.RESULTS_LIST);
this.resultsList.setAttribute('id', CLASSNAMES.RESULTS_LIST);

@@ -275,6 +283,8 @@ class AutocompleteUI {
results.forEach((result, index) => {
const li = document.createElement('li');
li.classList.add(CLASSNAMES.RESULTS_ITEM);
li.setAttribute('role', 'option');
li.setAttribute('id', `item-${index}`);
Copy link
Contributor

Choose a reason for hiding this comment

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

fyi we use the same class value for both class and id attributes for the input element but different values for this lielement. Should this be

Suggested change
li.setAttribute('id', `item-${index}`);
li.setAttribute('id', `${CLASSNAMES.RESULTS_ITEM}-${index}`);

to make it more consistent?

Copy link
Contributor

Choose a reason for hiding this comment

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

we should prob make this ${CLASSNAMES.RESULTS_ITEM}-${index} since id attributes should be unique. item-${index} might cause issues with existing ids

@@ -380,43 +391,41 @@ class AutocompleteUI {
// add class name to newly highlighted item
resultItems[index].classList.add(CLASSNAMES.SELECTED_ITEM);

// set aria active descendant
this.inputField.setAttribute('aria-activedescendant', `item-${index}`);
Copy link
Contributor

Choose a reason for hiding this comment

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

and if we wanna go with the above suggestion

Suggested change
this.inputField.setAttribute('aria-activedescendant', `item-${index}`);
this.inputField.setAttribute('aria-activedescendant', `${CLASSNAMES.RESULTS_ITEM}-${index}`);

@kochis kochis merged commit 94e267e into master Jun 27, 2024
3 checks passed
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.

2 participants