[UEPR-483] "Choose a Sprite" and "Choose a Backdrop" keyboard accessibility#433
Conversation
e37597f to
f2902ce
Compare
packages/scratch-gui/src/components/action-menu/action-menu.jsx
Outdated
Show resolved
Hide resolved
packages/scratch-gui/src/components/action-menu/action-menu.jsx
Outdated
Show resolved
Hide resolved
packages/scratch-gui/src/components/action-menu/action-menu.jsx
Outdated
Show resolved
Hide resolved
packages/scratch-gui/src/components/action-menu/action-menu.jsx
Outdated
Show resolved
Hide resolved
packages/scratch-gui/src/components/action-menu/action-menu.jsx
Outdated
Show resolved
Hide resolved
packages/scratch-gui/src/components/action-menu/action-menu.jsx
Outdated
Show resolved
Hide resolved
packages/scratch-gui/src/components/action-menu/action-menu.jsx
Outdated
Show resolved
Hide resolved
|
The latest commit fixes the following 3 bugs that existed:
What I did was remove onBlur logic and replace it in the following way - onBlur unites a few of the following cases:
|
KManolov3
left a comment
There was a problem hiding this comment.
Left a few minor comments, but otherwise the behavior looks very smooth to me now! 🙌
There's a lot of logic "under the hood" which may end up being finicky, but hopefully this doesn't end up getting changed very often.
| } else if (e.key === KEY.TAB) { | ||
| setIsExpanded(false); | ||
| focusItem(buttonRef.current); | ||
| } else if (e.key === KEY.ESCAPE) { |
There was a problem hiding this comment.
I see some possibly unintended behavior when clicking ESCAPE, after which attempting to TAB- I need to TAB twice for something to happen. It's more of a corner case, but might be worth fixing if it isn't too hard. Otherwise I am fine with leaving as is for now.
There was a problem hiding this comment.
Hmm, it seems to be another issue that appears on firefox but not chrome. Upon reconsideration, I am not sure if Escape behavior is something we want at all here. I mean there are other intuitive ways to focus away as a keyboard or mouse user, such as tab or clicking outside of the menu. What do you think?
There is the "we want to be able to focus the core option" argument but the bottom one already duplicates that behavior on every use of action menu.
A compromise would be "focus on the main button on escape but keep the menu open, since we can still enter it with arrows". Collapsing seems a little unnatural to me now.
packages/scratch-gui/src/components/action-menu/action-menu.jsx
Outdated
Show resolved
Hide resolved
| }), [] | ||
| ); | ||
|
|
||
| const handleItemMouseEnter = useCallback(index => () => { |
There was a problem hiding this comment.
Can you leave a comment why this is needed?
packages/scratch-gui/src/components/action-menu/action-menu.jsx
Outdated
Show resolved
Hide resolved
packages/scratch-gui/src/components/action-menu/action-menu.jsx
Outdated
Show resolved
Hide resolved
packages/scratch-gui/src/components/action-menu/action-menu.jsx
Outdated
Show resolved
Hide resolved
| @@ -222,12 +196,10 @@ const ActionMenu = ({ | |||
|
|
|||
| const handleClick = useCallback(e => { | |||
There was a problem hiding this comment.
Having a useCallback inside of a map is an antipattern - https://react.dev/reference/rules/rules-of-hooks#only-call-hooks-at-the-top-level. We should be able to extract this on top level.
| setTimeout(() => { | ||
| const focusedElement = document.activeElement; | ||
| focusedElement.blur(); | ||
| focusItem(focusedElement); | ||
| }, CLOSE_DELAY * 1.5); |
There was a problem hiding this comment.
nitpick: We could probably extract this into a function, since we use the same logic twice?
| const focusedElement = document.activeElement; | ||
| focusedElement.blur(); | ||
| focusItem(focusedElement); | ||
| }, CLOSE_DELAY * 1.5); |
There was a problem hiding this comment.
1.5 is a magic constant. Why 1.5 exactly - can we add a comment?
| }, CLOSE_DELAY * 1.5); | ||
| }, []); | ||
|
|
||
| useEffect(() => { |
There was a problem hiding this comment.
Can we add comments in what usecases the different useEffects will be relevant
…uepr-483-choose-a-sprite-and-backdrop-accessibility
| focusItem(focusedElement); | ||
| }, CLOSE_DELAY * 1.5); | ||
| }, []); | ||
| }, 500); |
There was a problem hiding this comment.
500 is also a magic constant 😅 I think it was a bit better when it was connected with the CLOSE_DELAY. But we can update this later.
92fedf5
into
scratchfoundation:release/UEPR-297-accessibility-improvements
Resolves
https://scratchfoundation.atlassian.net/browse/UEPR-483
Proposed Changes
Reason for Changes
Part of accessibility initiative for Scratch.