-
Notifications
You must be signed in to change notification settings - Fork 173
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): close dropdown on enter or tab key press #761
Conversation
When an autocomplete value is selected via the autocomplete's `setSelected()` method, the autocomplete's v-model value will usually be updated, and the dropdown will usually scheduled to be closed on the next tick. However, updating the v-model value triggers the v-model watcher, which would then schedule the dropdown to be open again on the next tick. This change updates the v-model watcher to not do anything when the new value is the same as the currently selected value.
If the autocomplete looses focus without a mouse click (eg because the user tabbed away from it), the dropdown would remain open. This change extends the standard onBlur handler to first close the dropdown (and then run the standard onBlur handling).
Pressing the tab key when the autocomplete input was focused moved the focus to autocomplete menu. This change removes the autocomplete menu and all of its options from the tab sequence.
Using the up & down keys to change the "hovered" state triggers a re-render of the autocomplete menu options -- but not of the autocomplete component itself. The autocomplete's own `onBeforeUpdate` handler is not called when this happens; and so using it to clear the `itemRefs` array resulted in the previous set of options not being removed. The main manifestation of this bug was that it was not possible to use the down key to access a selectable-footer option. This change clears the `itemRefs` array whenever the `setItemRef()` function is called for the first menu option; now the `itemRefs` array will be cleared both whenever the full autocomplete component is re-rendered, and whenever just the individual options are re-rendered.
When the `selectable-header` (or `selectable-footer` prop) is true, it was possible to use the up & down keys to turn on the visual "hovered" state for both the header (or footer) option and another regular option at the same time. This change centralizes the logic of setting the `hoveredOption`, `headerHovered`, and `footerHovered` refs in the `setHovered()` function, ensuring that only one can be set at a time.
The ARIA attributes used by the autocomplete menu and options represented the menu as if it were a standalone modal dialog. The change applies the Combobox Pattern from the ARIA Authoring Practices Guide to the autocomplete input, menu, and options -- which should allow assistive technologies to recognize the menu as a list of options available for the input, and to identify the currently "hovered" option. See https://www.w3.org/WAI/ARIA/apg/patterns/combobox/ for details.
✅ Deploy Preview for oruga-documentation-preview ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## develop #761 +/- ##
===========================================
- Coverage 54.62% 54.25% -0.37%
===========================================
Files 32 32
Lines 1461 1480 +19
Branches 519 527 +8
===========================================
+ Hits 798 803 +5
- Misses 663 677 +14
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
@justinludwig Well done PR. Thanks a lot for your effort!!! |
Fixes #707 with the following changes to the Autocomplete component:
Close after selection
When an autocomplete value is selected via the autocomplete's
setSelected()
method, the autocomplete's v-model value will usually beupdated, and the dropdown will usually scheduled to be closed on the
next tick. However, updating the v-model value triggers the v-model
watcher, which would then schedule the dropdown to be open again on the
next tick.
This change updates the v-model watcher to not do anything when the new
value is the same as the currently selected value.
Close on blur
If the autocomplete looses focus without a mouse click (eg because the
user tabbed away from it), the dropdown would remain open.
This change extends the standard onBlur handler to first close the
dropdown (and then run the standard onBlur handling).
Remove menu from tab sequence
Pressing the tab key when the autocomplete input was focused moved the
focus to autocomplete menu.
This change removes the autocomplete menu and all of its options from
the tab sequence.
This change also adds a
menuTabindex
prop to the Dropdown component(to enable the dropdown menu to be removed from the tab sequence).
Clear itemRefs on re-render
Using the up & down keys to change the "hovered" state triggers a
re-render of the autocomplete menu options -- but not of the
autocomplete component itself. The autocomplete's own
onBeforeUpdate
handler is not called when this happens; and so using it to clear the
itemRefs
array resulted in the previous set of options not beingremoved.
The main manifestation of this bug was that it was not possible to use
the down key to access a selectable-footer option.
This change clears the
itemRefs
array whenever thesetItemRef()
function is called for the first menu option; now the
itemRefs
arraywill be cleared both whenever the full autocomplete component is
re-rendered, and whenever just the individual options are re-rendered.
Select head/foot exclusively of other options
When the
selectable-header
(orselectable-footer
prop) is true, itwas possible to use the up & down keys to turn on the visual "hovered"
state for both the header (or footer) option and another regular option
at the same time.
This change centralizes the logic of setting the
hoveredOption
,headerHovered
, andfooterHovered
refs in thesetHovered()
function, ensuring that only one can be set at a time.
Apply ARIA combobox pattern
The ARIA attributes used by the autocomplete menu and options
represented the menu as if it were a standalone modal dialog.
The change applies the Combobox Pattern from the ARIA Authoring
Practices Guide to the autocomplete input, menu, and options -- which
should allow assistive technologies to recognize the menu as a list of
options available for the input, and to identify the currently "hovered"
option.
See https://www.w3.org/WAI/ARIA/apg/patterns/combobox/ for details.
This change also adds a
menuId
prop to the Dropdown component(to allow the combobox to reference the dropdown menu by id).