-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Improve keyboard handling and accessibility for Select.svelte and refactor #2811
Conversation
better comments to document tagindex reasoning
allow focus to TagsSelectedButton with Shift+Tab and Enter or Space to show popover
ideally should replace with with a11y-click-events-have-key-events is explicitly ignored as the alternative (adding ) seems more clunky
cannot focus on these buttons, so no key event handling needed (keyboard editting already possible by just typing in the field) widget already properly follows ARIA APG Spinbutton pattern
Still need to fix focus and handle roles and attributes
focus is janky because you need to wait until after the listed options load and for some reason that needs a tiny delay on onMount I think this technically violates a11y, but it really doesn't since the delay is literally zero. But the code still needs it to happen.
+ started roles and a11y
Thanks Ben! I'll give this a proper review in the next few days after 23.10.1 is out the door, and your previous PR has been merged in. |
2cc4784
to
d169470
Compare
I've given this a test. Some thoughts:
|
ts/lib/keys.ts
Outdated
* Builds function for `on:keydown` event to call `callback` if a key from `keys` was pressed | ||
*/ | ||
export function onSomeKey(callback: () => void, ...keys: string[]): (event: KeyboardEvent) => void { | ||
// I really want to generalize this as some structure of ([list of key combinations], function) pairs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I recommend reverting this change. We're not ready to introduce custom keyboard shortcuts yet and only have one caller, so this doesn't meet the rule of three, and this function can't handle things like modifier keys.
Alright, those should be fixed now. I also realized that the arrow keys weren't properly scrolling through the page and quickly fixed that |
const roles = { | ||
option: "option", | ||
popover: "listbox", | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please inline the values from ids
and roles
in the usage sites, and remove these lines, as using constants for DOM properties is not a pattern that the rest of the codebase uses (and you've been inconsistent with usage here too, using role="combobox" below.
One more issue I spotted: if you tab down to 'insertion order' in the deck options and hit enter or space, you then have to hit down twice before a highlight/focus appears. |
Another minor issue: if you tab down to a lower dropdown that requires screen scrolling, then after selecting it and using the arrow keys, the page scrolls up/down as you change the focused element. It would be nice if the scrolling could be easily prevented when the new element is already visible. |
ac6af1f
to
7bc4130
Compare
I'm not really sure how to replicate what you had in that last comment. It did bring my attention to some weird scrolling behavior going on that I fixed by only scrolling if the element is not visible which seems to work much better. |
Thanks Ben, this is looking pretty good at this point, and the scrolling issue I mentioned has been fixed. The one remaining issue I spotted is that after selecting a dropdown with the keyboard, the up/down arrows always start from the top element. If it's not too difficult to have the selection start from the currently-active element (and ideally, show the focus outline prior to the user pressing up/down), that would make it feel even more polished. |
Up/Down Arrows: start selection on active option Enter/Space/Click: no initial selection, down arrow to first option, up arrow to last option
Yeah, I didn't really know how exactly to handle that, the APG are a little vague so I guess it is more stylistic. I decided to keep Enter/Space/Click as just opening the popup without focusing a selection and you can then hit down arrow to go to the first item or up arrow to go to the last item. If you would prefer that should actually be from the active element, I can do that pretty easily. |
Hello, I'm Alex, a low-vision person and accessibility specialist. I'm new to Anki though. I hope I'm right in the thread. If you're testing "Select-Only Combobox" from APG: if you select a value, close the list and open it again you go back to the previously selected value, which is the result you expect as a end-user. It's not very clear but APG says:
Going back to the top is a change in focus. The document also says:
Kind regards, |
Thanks Alex - specialist input is much appreciated! The example combobox on that page does behave like I would expect, with the focus being on the currently-selected element when opened. Ben: if you're not sure how to implement that, I'd suggest creating a new issue that describes what is still to be done, and then we can merge this in as-is, since it's still an improvement over what we had before. |
…es use the previous selected
Alex, thanks for the feedback. I am only somewhat familiar with accessibility and generally better at telling if something is just frustrating to use. I believe I already have the Dae, I was just a little busy the last few days so couldn't work on it. I think it should be better now though. If there are still issues, I think it would be best to make it an open issue and merge as-is. Also, I'm thinking it may be a good idea to open a general accessibility issue thread to collect any of the many little problems (or that's a label? or maybe individual issues? idk github too well). It would just be useful to easily identify anything that has accessibility or other UX issues. |
Updated behavior is much nicer - thanks for figuring that out! I've added an a11y label that you can assign to new tickets. For tracking particular issues, separate tickets are better, as they can be individually closed. If you feel a general issue is also required to discuss general a11y topics rather than specific problems, you're welcome to create that too. |
As noted in #2802, I noticed Select.svelte has really bad keyboard handling (for example, you could select an option, but the popover wouldn't close) and generally didn't follow a11y guidelines as a combobox widget. I fixed this to adhere to the ARIA APG combobox pattern. To avoid a spaghetti mess of stores trying to pass values around, I encompassed SelectOption within Select and adjusted all of where Select is used accordingly.
Known Issues:
aria-labelledby
, butaria-label
works) but I'm not sure how to identify how that should be done for the many different ways Select is used.focus
class to do that. I tried to get it to resemble hovering over the option, however, they are very subtly different in realization.This PR includes commits currently in review in #2787 because... I'm not good at git, sorry. Suggestions on good branch structuring would be appreciated. (I suppose just 1 branch for each PR, but I didn't think about that for #2787 and that has come back to bite me in the butt, sorry again.)