-
Notifications
You must be signed in to change notification settings - Fork 11
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
Conversation
There was a problem hiding this 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?
src/ui/autocomplete.ts
Outdated
@@ -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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this.resultsList.classList.add('id', CLASSNAMES.RESULTS_LIST); | |
this.resultsList.setAttribute('id', CLASSNAMES.RESULTS_LIST); |
src/ui/autocomplete.ts
Outdated
@@ -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}`); |
There was a problem hiding this comment.
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 li
element. Should this be
li.setAttribute('id', `item-${index}`); | |
li.setAttribute('id', `${CLASSNAMES.RESULTS_ITEM}-${index}`); |
to make it more consistent?
There was a problem hiding this comment.
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
src/ui/autocomplete.ts
Outdated
@@ -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}`); |
There was a problem hiding this comment.
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
this.inputField.setAttribute('aria-activedescendant', `item-${index}`); | |
this.inputField.setAttribute('aria-activedescendant', `${CLASSNAMES.RESULTS_ITEM}-${index}`); |
The main fix is to change from
event.code
toevent.key
for handling keyboard events, which was breaking on Windows/Edge.Other enhancements are additional aria-roles for accessibility.