ComboBox accessibility: Tabbing/dismissing callout toggle selection
Environment Information
- Package version(s): 7.129.0
- Browser and OS versions: Chrome 84.0.4147.125, Windows 10
Describe the issue:
In ComboBox, with multiselect and freeform allowed, if you're focused on an option, pressing tab unexpectedly toggles the selection.
Please provide a reproduction of the issue in a codepen:
Repro: https://codepen.io/erichdev/pen/yLOaqbr
- Select a ComboBox option and close options callout (mouse at this point is fine)
- Focus on ComboBox input
- Press enter to open options
- Arrow down to selected option
- Press TAB to move focus
- The selected option is no longer selected.
Actual behavior:
When focused on a ComboBox option, pressing TAB will toggle the selection.
Expected behavior:
Tab should move focus to the next element without affecting selection. While focused on an option, pressing Enter correctly toggles selection; tab should not affect selection.
Documentation describing expected behavior
A similar repro is:
- Open the ComboBox options callout.
- Keyboard arrow down to any option.
- Press enter to select the option.
- Click outside the ComboBox to dismiss the callout.
- The option is no longer selected.
Seems the values are being updated on dissmiss/on blur.
@erichdev Thanks for the great repo steps in your codepen!
@khmakoto - I believe the main issue is that the user expectation here is that if you arrow key to an option in the ComboBox and press Tab it should behave as if you pressed Esc, but it actually selects the option... which feels strange as Enter is the primary keyboard selection method.
@paulgildea This appears to be expected behavior. There are explicit checks to automatically select an option if focus is lost, even if it's a multiselect. @jspurlin do you have any insight as to the expected behavior? We can remove that blur autoselect, which I think makes the most sense, but that could be seen as a breaking change depending.
@paulgildea This issue was raised by Teams lists app ship build test pass. it is a bit weird if this is by design. It means if user select the option then try to move focus to next element, it always get opposite result. Unless user knew by click tab it will select current focused option therefore if it intends to select A, user must NOT select A in UI but put focus on A then click Tab so it can select A and close the combobox move focus to next element? that seems hard to use?
@paulgildea @joschect @khmakoto I think the problem here is the onChange function is fired twice if both 'allowFreeForm' and 'multSelect' is enabled.
In the onChange function, when we handle updating current selected items, we do not know if it's a select action or an un-select action. Depending on if the changed option is in the selectedKeys, we add/remove the option. If the option changed is in current selected keys, we assume user is trying to remove this selection. While if the option changed is not in current selected keys, we assume user is trying to add this selection. Evoking onChange twice means, (assume we want to select an option) you first add the option into the selectedKeys (correct behavior) then you remove the option from the selectedKeys (un-do the previous step which is not expected).
I think the fix should prevent evoking onChange function firing again when tab is pressed.
Here is an example showing onChange fired twice: https://codepen.io/ycoco/pen/XWjvZaG?editors=1111
(With allowFreeForm off and multiSelect on, it works as expected and onChange is only fired once. https://codepen.io/ycoco/pen/OJRKQNW)
Because this issue has not had activity for over 150 days, we're automatically closing it for house-keeping purposes.
Still require assistance? Please, create a new issue with up-to date details.