Repository navigation
Give SuggestBox the ARIA combobox pattern - #26
Conversation
The text box gets role="combobox", aria-autocomplete="list" and aria-expanded. DefaultSuggestionDisplay sets aria-expanded and aria-controls as its popup opens and closes, and keeps aria-activedescendant on the box pointing at the highlighted suggestion, whether the arrow keys, mouse hover or auto-select moved it. The list is a listbox named after the box's label, and its items are options with aria-selected. Addresses rstudio/rstudio#19254.
The combobox pattern expects Escape to close an open list. The key event is prevented when it does, so handlers that run later can tell it was used. With the list closed, Escape is left alone, so that a dialog can still close. Addresses rstudio/rstudio#19254.
With an oracle that answers asynchronously, a response that arrived after Escape closed the list reopened it. Escape now drops responses to requests already made; the next request, from typing or showSuggestionList(), shows its response as before. Addresses rstudio/rstudio#19254.
Before, the next request after Escape cleared the flag that dropped earlier responses, so a response requested before Escape could still arrive after a newer one and replace its suggestions. Each request's callback now records how many times Escape had been pressed, and drops its response if Escape has been pressed since. Addresses rstudio/rstudio#19254.
The table already had role="presentation", but Chrome ignored role="option" on the SuggestBox cells inside it, exposing them as nameless generic elements, so VoiceOver couldn't announce a highlighted suggestion whose text had markup, as in the Install Packages dialog. Chrome accepts an option only if every element between it and its listbox is explicitly presentational, so the tbody and rows now are too. Addresses rstudio/rstudio#19254.
selectItem(null) left the menu's aria-activedescendant naming the item that was last highlighted, even after clearItems() removed it. That happens on every keystroke in a SuggestBox list, whose items are rebuilt each time. Addresses rstudio/rstudio#19254.
gtritchie
left a comment
There was a problem hiding this comment.
Review findings, checked against the source and the rstudio bugfix/suggestbox-combobox branch. None is a regression for RStudio today; the first is the one most worth acting on.
|
|
||
| void showSuggestions(String query) { | ||
| // A response that arrives after Escape would reopen the list | ||
| final int escapesAtRequest = escapeCount; |
There was a problem hiding this comment.
The stale-response guard only covers Escape. A late async response still reopens the list after it closes any other way: Tab or Enter with no selection, picking a suggestion, or an autoHide click.
Example: HelpSearchOracle is async (server_.suggestTopics). Type in Help search, press Tab before the response arrives, and the response calls display.showSuggestions, which shows the list and sets aria-expanded="true" on a box that no longer has focus. That path predates this PR, but a request-generation counter bumped on every hide and every new request would fix it along with Escape (and out-of-order responses), instead of special-casing Escape.
There was a problem hiding this comment.
Fixed in 97de384. Each request now takes a new generation, and Escape, Tab, Enter, choosing a suggestion and blur start another, so only the latest request's response shows, and only while focus is still in the box. That also drops out-of-order responses. The generation is advanced in SuggestBox rather than from the popup's close handler: the list often isn't showing yet when Tab is pressed, so no close event fires, and the close handler also runs for the internal hide on every refresh. Checked in RStudio by delaying suggest_topics: Tab out of Help search before the response and the list doesn't open; stay in the box and it does.
| // The combobox pattern; DefaultSuggestionDisplay keeps the box's expanded | ||
| // and highlight state current as its list opens, changes and closes. | ||
| ComboboxRole role = Roles.getComboboxRole(); | ||
| role.set(box.getElement()); |
There was a problem hiding this comment.
Every box gets role="combobox" and aria-expanded="false" here, but only DefaultSuggestionDisplay ever updates aria-expanded, aria-controls and aria-activedescendant. SuggestionDisplay can be subclassed directly (its abstract methods are protected), and such a display leaves the box announced as a collapsed combobox while its list is open.
RStudio isn't affected: its three displays all extend DefaultSuggestionDisplay and call super.showSuggestions. Keeping this state in SuggestionDisplay or SuggestBox would cover every display.
There was a problem hiding this comment.
Fixed in 149259b, by narrowing rather than moving the state: SuggestBox sets the combobox attributes only when its display is a DefaultSuggestionDisplay, the one display that keeps them current. Moving the state into SuggestionDisplay would need new API to expose the list element, which no RStudio display needs. bea4066 applies the same condition to Down Arrow opening the list, since other displays may not report whether their list is showing.
| suggestionPopup.addCloseHandler(new CloseHandler<PopupPanel>() { | ||
| public void onClose(CloseEvent<PopupPanel> event) { | ||
| if (lastSuggestBox != null) { | ||
| setListShown(lastSuggestBox.getElement(), false); |
There was a problem hiding this comment.
When the list is already open, showSuggestions calls suggestionPopup.hide() before repopulating it (line 508), and PopupPanel.hide fires CloseEvent synchronously. So each keystroke with the list open runs this handler: it clears aria-expanded, aria-controls and aria-activedescendant, then setListShown(true) restores them and runs nameListAfter (a box.labels lookup) again. The end state is unchanged, so this is wasted work rather than a visible bug. Chrome builds its accessibility tree after the script finishes, so screen readers probably don't announce it. Skipping the close handling for this internal hide would avoid it.
There was a problem hiding this comment.
Leaving this as is. The end state is the same, Chrome builds its accessibility tree after the script finishes, and with 97de384 correctness no longer depends on the close handler, so skipping it for the internal hide would only save the work.
| // Prevented, so that handlers that run later, such as those on | ||
| // ancestors, can tell that this Escape closed the list | ||
| if (isSuggestionListShowing()) { | ||
| display.hideSuggestions(); |
There was a problem hiding this comment.
After Escape there's no keyboard way to reopen the list. moveSelectionDown/moveSelectionUp do nothing while it's hidden, and keyup's refreshSuggestions returns early because the text equals currentText, so the user has to edit the text. The APG list-autocomplete example opens the list on Down Arrow when it's closed. A list closed by autoHide already had this gap before this PR, but Escape now makes it common.
There was a problem hiding this comment.
Fixed in 392ed57: Down Arrow on a closed list requests suggestions, without moving the highlight, and without preventDefault, so a TextArea box still moves its caret. bea4066 limits this to DefaultSuggestionDisplay. In RStudio, Down reopens Help search's list after it closes; filter boxes, which use NoSuggestionsOracle, are unaffected.
|
|
||
| String labelledBy = box.getAttribute("aria-labelledby"); | ||
| String label = box.getAttribute("aria-label"); | ||
| if (!labelledBy.isEmpty()) { |
There was a problem hiding this comment.
This copies the box's aria-labelledby verbatim. If it includes the box's own id (the aria-labelledby="labelId inputId" pattern), the listbox is named after the typed text, which the comment above says this avoids (e.g. "Packages gg", changing on every keystroke). I didn't find this pattern on any RStudio suggest box; dropping box.getId() from the IDREF list would rule it out.
There was a problem hiding this comment.
Fixed in 2dcde21: the box's own id is dropped when copying aria-labelledby. If it was the only id, the list is named from the box's aria-label or elements instead.
| */ | ||
| private void nameListAfter(Element box) { | ||
| Element list = suggestionMenu.getElement(); | ||
| list.removeAttribute("aria-label"); |
There was a problem hiding this comment.
Nit: this method uses raw setAttribute/removeAttribute for aria-label and aria-labelledby, while the rest of the PR goes through Roles. RoleImpl has setAriaLabelProperty, setAriaLabelledbyProperty(Id...), removeAriaLabelProperty and removeAriaLabelledbyProperty, so Roles.getListboxRole() can do this the same way.
There was a problem hiding this comment.
Done in 2dcde21: nameListAfter now uses ListboxRole's label methods.
| * through here. | ||
| */ | ||
| @Override | ||
| public void selectItem(MenuItem item) { |
There was a problem hiding this comment.
Nit: super.selectItem still sets aria-activedescendant on the listbox element (MenuBar.selectItem, via the menubar role), alongside the new one on the combobox. The listbox never has focus, so its copy does nothing, and testActiveDescendantFollowsHighlight has to assert that both are cleared. Harmless, but it's a second copy of the same state.
There was a problem hiding this comment.
Fixed in 9e054b7: SuggestionMenu.selectItem removes the listbox's copy after super, and the extra SuggestBoxTest assertion now checks the list never has one. MenuBarTest.testSelectItem covers MenuBar clearing its own aria-activedescendant when nothing is selected.
Only Escape dropped responses to requests already made. Pressing Tab or Enter, choosing a suggestion, or leaving the box before an asynchronous oracle answered still opened the list when the response came, on a box that might no longer have focus. A response to an older request could also replace a newer one's. Each request now takes a new generation, and Escape, Tab, Enter, choosing a suggestion and blur start another, so only the latest request's response shows, and only while the user is still in the box. Addresses rstudio/rstudio#19254.
SuggestBox gave every box role="combobox" and aria-expanded="false", but only DefaultSuggestionDisplay updates aria-expanded, aria-controls and aria-activedescendant. A box with another SuggestionDisplay subclass always read as a collapsed combobox, even with its list open. Such a box now keeps its plain role. Addresses rstudio/rstudio#19254.
Once Escape closed the list, the only way to get it back was to change the text: the arrow keys only moved within an open list, and keyup didn't request suggestions for unchanged text. Down Arrow now requests suggestions when the list is closed, as in the combobox pattern, without moving the highlight. Addresses rstudio/rstudio#19254.
The listbox copied the box's aria-labelledby as is. With the common aria-labelledby="labelId boxId" pattern, that named the list after the typed text as well as the label. The box's own id is now dropped, and if it was the only one, the list is named from the box's aria-label or <label> elements instead. The list's name is also set through the Roles API, like the rest of SuggestBox's ARIA. Addresses rstudio/rstudio#19254.
MenuBar.selectItem sets aria-activedescendant on the menu, so the listbox carried a copy of the box's. Focus stays in the box, so the list's copy did nothing. SuggestionMenu now removes it, and MenuBarTest covers MenuBar clearing its own when nothing is selected, which SuggestBoxTest checked before. Addresses rstudio/rstudio#19254.
SuggestionDisplay.isSuggestionListShowing() returns false unless a display overrides it, so a custom display that didn't had every Down Arrow request suggestions instead of moving its highlight. Only DefaultSuggestionDisplay, which reports whether its list is showing, opens it on Down Arrow now. Addresses rstudio/rstudio#19254.
Since 89fc3b8, MenuBar refocuses the parent menu whenever a submenu closes other than by autoHide, while upstream does so only with focus on hover enabled. The test still expected upstream's behavior when hovering closes a submenu, so it has failed since then. It now expects the menu bar to take focus at that step.
FocusImplSafari, which Chrome also uses, focuses from a setTimeout, so testSetFocusOnHoverDisabled's final check that the menu bar has focus would fail in that permutation. It now runs deferred, as in testSetFocusOnHoverEnabled.
gtritchie
left a comment
There was a problem hiding this comment.
Second pass after the latest commits: they fix six of the seven earlier points (the per-keystroke ARIA rebuild is still there, which is fine to leave). Two small things in the new code below.
| // whether their list is showing, so they keep moving the highlight. | ||
| if (display instanceof DefaultSuggestionDisplay | ||
| && !isSuggestionListShowing()) { | ||
| showSuggestionList(); |
There was a problem hiding this comment.
showSuggestionList() clears currentText, so Down on a closed list always sends a new request, even when one for the same text is still waiting. With HelpSearchOracle, typing "plot" and pressing Down before the response arrives drops that request and sends an identical one. On text with no suggestions (hideWhenEmpty keeps the list closed), every Down press sends another server request. This also doesn't preventDefault(), so in a TextArea-backed box Down both opens the list and moves to the next line. The macOS caret-to-end movement isn't new; the old code didn't prevent Down on a closed list either.
One option: skip the request when a request for the current text is still pending, and call event.preventDefault() when Down opens the list.
There was a problem hiding this comment.
Fixed in 2ac48b1. SuggestBox now notes when the latest request's response is still due (cleared when it arrives, or when Escape, Tab, Enter, choosing a suggestion or blur drop it), and Down on a closed list only requests when nothing is due, leaving a pending response to open the list. In RStudio, with suggest_topics delayed, typing "plot" and pressing Down at once sends one request per prefix, with no repeat for "plot", and the list opens when the response arrives.
Down also now shares the preventDefault() check with moving: if the list is showing afterward, as with a synchronous oracle, the default is prevented. With an asynchronous oracle nothing is known when the key is pressed, and preventing it unconditionally would stop a TextArea-backed box with no suggestions from moving between lines, so that case still moves the caret, as before this PR.
Leaving the repeated requests on text with no suggestions: avoiding them would mean remembering empty results per text, and each is one cheap request per Down press.
| // As in the combobox pattern, Down Arrow opens a closed list, | ||
| // such as one dismissed with Escape. Other displays may not report | ||
| // whether their list is showing, so they keep moving the highlight. | ||
| if (display instanceof DefaultSuggestionDisplay |
There was a problem hiding this comment.
Nit: this and the constructor (line 864) both special-case DefaultSuggestionDisplay with instanceof. SuggestionDisplay already has package-private hooks (isAnimationEnabledImpl, setPopupStyleNameImpl), so a package-private boolean managesComboboxState() returning false, overridden to true in DefaultSuggestionDisplay, would keep the decision in one place without touching the public API.
There was a problem hiding this comment.
Done in 664e44d: a package-private SuggestionDisplay.managesComboboxState(), false by default and true in DefaultSuggestionDisplay, now decides both, alongside the existing *Impl hooks.
SuggestBox checked instanceof DefaultSuggestionDisplay in two places to decide whether a display keeps the box's combobox state current. A package-private SuggestionDisplay.managesComboboxState(), which DefaultSuggestionDisplay overrides, now makes that decision in one place, as isAnimationEnabledImpl() does for animation, without adding public API. Addresses rstudio/rstudio#19254.
Down Arrow on a closed list called showSuggestionList(), which sends a new request even when one for the same text is still waiting on the oracle. That dropped the pending request and sent an identical one, so typing and pressing Down at once roughly doubled the wait with a server oracle such as Help search's. Down now leaves a request whose response is still due to open the list. Down also prevents its default action whenever the list is showing afterward, as when moving within it, so a list that opens at once doesn't also move the caret. Addresses rstudio/rstudio#19254.
The new build adds the ARIA combobox pattern to SuggestBox: the text box is a combobox whose aria-activedescendant follows the highlighted suggestion in a named listbox of options. Escape closes the list and Down Arrow reopens it, and late responses no longer reopen a dismissed list. MenuBar's table rows are also marked presentational, so Chrome exposes the suggestions as options (rstudio/gwt#26). Addresses #19254.
* Keep filter-only search boxes out of the combobox role The GWT fork now gives every SuggestBox input role="combobox". Search boxes whose oracle never suggests, such as the Environment and Packages filters, would then announce as comboboxes whose list never opens. SearchWidget.NoSuggestionsOracle marks those boxes, and SearchWidget removes the combobox attributes from them. The ten filter-only callers now use it in place of their own no-op oracles. Addresses #19254. * Keep SearchWidget's two-step Escape with SuggestBox closing on Escape The GWT fork's SuggestBox now closes its list on Escape, in a handler that runs after SearchWidget's but before SearchWidget's deferred command. That command checked whether the list was showing, so it would see it closed and dismiss the whole search, such as Go to File, on the first Escape. SearchWidget now reads the list state when the key is pressed, so the first Escape still closes the list and clears the text. Addresses #19254. * Set aria-modal only on alert dialogs Since #19251, every modal dialog and alert dialog set aria-modal="true". In Chrome on macOS, that hides anything attached outside the dialog from VoiceOver while focus stays inside it, so the suggestion lists in Install Packages and Go to File/Function, which are attached to the body, weren't announced. Removing aria-modal from the dialog made VoiceOver announce them; claiming the list with aria-owns didn't. Only alert dialogs need aria-modal, for axe to treat them as open modals; it already does for role="dialog", and the rest of the page is inert either way. Addresses #19254. * Announce the highlighted tab in the tab overflow search The search box in the source tab overflow popup filters the popup's menu of open documents, and the arrow keys move the menu's highlight while focus stays in the search box. Nothing tied the box to the menu, so screen readers announced nothing as the highlight moved. Its oracle never suggests, so SuggestBox's own list never opened either, and the box read as a collapsed combobox. The box now uses NoSuggestionsOracle and is a combobox for the menu, as the Git branch menu's search box is: aria-controls names the menu, and aria-activedescendant follows the highlight, which DocsMenu now reports with selection events. Filtering out the highlighted document clears the highlight. Addresses #19254. * Use GWT 2.13.1-parrot-balsam-2 The new build adds the ARIA combobox pattern to SuggestBox: the text box is a combobox whose aria-activedescendant follows the highlighted suggestion in a named listbox of options. Escape closes the list and Down Arrow reopens it, and late responses no longer reopen a dismissed list. MenuBar's table rows are also marked presentational, so Chrome exposes the suggestions as options (rstudio/gwt#26). Addresses #19254. * Answer filter-only search boxes with an empty suggestion list NoSuggestionsOracle never called back, so SuggestBox kept waiting for a response. The oracles it replaced each answered with an empty list. Addresses #19254 * Share the search-box-drives-menu ARIA wiring The tab overflow search and MenuSearchHeader each set up the combobox role the same way, and DocsMenu and ScrollableToolbarMenuBar each fired SelectionEvent as the highlight moved. SearchWidget.controlMenu() now does the former, and BaseMenuBar the latter. Addresses #19254 * Name the tab overflow menu As with the menus under MenuSearchHeader, screen readers otherwise announce an unnamed menu. Addresses #19254 * Use DomUtils.ensureHasId in SearchWidget.controlMenu Addresses #19254 * Fire BaseMenuBar's SelectionEvent only when the highlight moves MenuBar.selectItem does nothing when the item is already highlighted, such as when a highlighted item is clicked, but the event fired anyway. Addresses #19254 * Test SearchWidget's combobox role and two-step Escape The first Escape relies on SearchWidget's handler reading whether the list is showing before SuggestBox's own handler closes it. Addresses #19254 * Correct the comment on BaseMenuBarTests' clearing check The first selectItem(null) clears a highlight, so it fires; only the second is unchanged. Addresses #19254
Gives
SuggestBoxthe ARIA combobox pattern, so screen readers announce its suggestions. Before, the text box had no combobox semantics and nothing pointed at the highlightedmenuitemin the popup, so arrowing through suggestions announced nothing. Addresses rstudio/rstudio#19254.Changes
SuggestBoxgives its text boxrole="combobox",aria-autocomplete="list"andaria-expanded="false"when its display keeps that state current:SuggestionDisplay.managesComboboxState(), a package-private hook thatDefaultSuggestionDisplayoverrides. A box with another display keeps its plain role.DefaultSuggestionDisplaysetsaria-expanded="true"andaria-controlson the box when its popup shows. ACloseHandleron the popup clears them, andaria-activedescendant, however it closes:hideSuggestions(), autoHide, or choosing a suggestion. A display shared by two boxes moves this state to the box it's showing for.aria-activedescendanton the box follows the highlighted suggestion.SuggestionMenuoverridesselectItem, which the arrow keys, mouse hover, mouseout, auto-select andclearItems()all go through, and removes the copy thatMenuBarsets on the list, which never has focus.listbox, named after the box's label: itsaria-labelledby(leaving out the box's own id, which would add the typed text), else itsaria-label, else its<label>elements. Items areoptions witharia-selected.preventDefault(), so later handlers can tell it was used. With the list closed, Escape is left alone, so a dialog can still close.DefaultSuggestionDisplay, unless a response is still due, which then opens it. Down prevents its default action whenever the list is showing afterward.MenuBarmarks its table'stbodyand rowsrole="presentation", not just the table. Chrome only acceptsrole="option"when every element between it and itslistboxis explicitly presentational; otherwise it exposes each option as a namelessgeneric.MenuBar.selectItem(null)removes the menu'saria-activedescendant, which otherwise named the last highlighted item, even afterclearItems()removed it.MenuBarTest.testSetFocusOnHoverDisablednow expects the fork's behavior: since 89fc3b8, a submenu closing other than by autoHide refocuses its parent menu, even with focus on hover disabled. It had failed since then.Behavior changes
SuggestBoxwith aDefaultSuggestionDisplayis a combobox, including ones whose oracle never suggests. RStudio removes the attributes from its filter-only search boxes (SearchWidget.NoSuggestionsOracle, on the rstudiobugfix/suggestbox-comboboxbranch).SuggestBoxignored Escape, and Down did nothing with the list closed.showSuggestionList()requests them again.Testing
SuggestBoxTestpasses (35/35, 17 new).MenuBarTestpasses (37/37).0f4509f7b, together with the rstudio branch, tested with VoiceOver in Chrome: highlighted suggestions are announced in Install Packages, the Help pane search, Go to File/Function, the data viewer's Go to column, and the visual editor's code block language. Escape closes the list first, and the dialog or search on the second press.optionnamed after its text, and the list is named after the box's label and has noaria-activedescendantof its own. Down Arrow reopens Help search's list. With Help'ssuggest_topicsRPC delayed, tabbing out before the response keeps the list closed, while staying in the box shows it, and typing "plot" then pressing Down at once sends no repeat request.aria-modalonrole="dialog"dialogs. In Chrome on macOS,aria-modalhid the suggestion lists of boxes in dialogs from VoiceOver, because the popup is attached to the body, outside the dialog;aria-ownsdidn't help.