awesomplete icon indicating copy to clipboard operation
awesomplete copied to clipboard

aria-selected, mouse events, and a smidgen of confusion

Open fractaledmind opened this issue 9 years ago • 2 comments

I believe that I have hit a bug, but I'm not 100% certain how to fix it, as I don't fully understand the purpose of the source code around applying the aria-selected attribute.

First, the bug: when using the keyboard to navigate the dropdown suggestions, aria-selected is set to true for the item that I select (via "enter"). When I use the mouse, however, to select an item from the dropdown, aria-selected remains false for that item.

The reason is fairly simple, but this is where the intentionality of the code confuses me a bit. The aria-selected attribute is only changed in the goto prototype method at line 189. The goto method isn't called directly in any of the instance event bindings, but is instead called from either next, previous, or open, and only from either next, previous, open. What is clear is that the aria-selected attribute is only set as the user keyboard navigates the dropdown items.

Notably, however, setting that attribute doesn't occur in the select method. So, it is really a happy coincidence that the selected item is marked as aria-selected="true", since it is given that attribute when you keyboard-navigate to it via the up or down arrow, and nothing happens to change it when you hit "enter". Moreover, this clearly leads to the bug described, as the mouse select only fires the select method, so goto isn't called to set the attribute.

The naive solution is simply to duplicate the one line of code that sets the attribute in the select method. This isn't really DRY, however. We could also call to goto from select, but that seems semantically odd and unnecessary. Also, I have tried to do some research to see if there is an ARIA attribute that maps better to "highlighted" that could be used in the goto method, while aria-selected is only set in the select method, but I couldn't really find anything (aria-activedescendant seemed close, but doesn't seem quite right, but I'm nothing close to an ARIA expert).

So, I believe this is a bug. I'm happy to fix it and put in a PR. I just don't know how it ought best to be fixed.

stephen

fractaledmind avatar Mar 17 '16 14:03 fractaledmind

I believe this is a bug too. I shouldn't be able to arrive in a state where my keyboard has something selected and my mouse has something else selected.

default-state

bholtbholt avatar Apr 06 '18 21:04 bholtbholt

This is possibly an oversight on my behalf, when working solely on aria stuff for keyboard navigation. I've simply been so concentrated on that, I missed that it should rightly be set for mouse too. Probably up to @LeaVerou to choose which solution is preferred.

stephenkeable avatar Apr 07 '18 10:04 stephenkeable