Fix VoiceOver + Safari: menu closes on Down Arrow#791
Open
AntoineGirard wants to merge 1 commit into
Open
Conversation
✅ Deploy Preview for accessible-autocomplete ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #247
Problem
When using VoiceOver on macOS with Safari, Firefox or Chrome, pressing the Down Arrow key while the autocomplete input is focused causes the suggestion menu to close immediately instead of navigating into the list.
The root causes are:
Missing
aria-haspopup="listbox"— without this attribute, VoiceOver does not recognise the input as an ARIA 1.2 combobox and falls back to its default behaviour for a plain text input. On Down Arrow, it moves its virtual cursor to the next element in the page rather than navigating the suggestion list.Race condition in
handleInputBlur— when VoiceOver navigates away from the input, ablurevent fires before Preact has a chance to commit thesetStatequeued byhandleDownArrow. At the timehandleInputBlurreadsthis.state.focused, it still holds−1(the input), sofocusingAnOptionisfalseand the menu is closed.Spurious
clickevents from VoiceOver — VoiceOver fires syntheticclickevents (event.detail === 0) as it moves its virtual cursor across options, unintentionally confirming a selection before the user has made one.This issue has been open since January 2022 and is labelled⚠️ high priority. PR #348 (superseded by #355) had already identified the combobox role placement; this PR picks up the remaining work.
Changes
aria-haspopup="listbox"added to the input (src/autocomplete.js)Completes the ARIA 1.2 combobox pattern on the
<input>element. The attribute was already partially in place (role="combobox",aria-expanded,aria-controls,aria-autocomplete,aria-activedescendant) butaria-haspopupwas missing, preventing VoiceOver from treating the field as a combobox.handleInputBlur—relatedTargetguard + deferred state readhandleOptionBlur.setTimeout(..., 0)so that anysetStatequeued by a concurrentkeydownhandler is flushed beforethis.state.focusedis read. This eliminates the race condition where VoiceOver firesblurbefore Preact commits the update fromhandleDownArrow.handleOptionClick— synthetic click guardBlocks synthetic clicks generated by VoiceOver's virtual cursor. The
event.type === 'click'guard is intentional:handleEnterandhandleSpacecallhandleOptionClickwith aKeyboardEvent(whosedetailis also0), so keyboard selection is unaffected.Testing
VoiceOver (macOS) — Safari and Chrome
Regression — keyboard (no AT)
confirmOnBlur: false)Regression — mouse
Regression — other screen readers