-
Notifications
You must be signed in to change notification settings - Fork 117
[UEPR-445] Ensure topbar is navigable via tab navigation #403
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
base: develop
Are you sure you want to change the base?
[UEPR-445] Ensure topbar is navigable via tab navigation #403
Conversation
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.
Pull request overview
This PR implements keyboard navigation and accessibility improvements for the top navigation bar, enabling users to navigate menu items using Tab and arrow keys. The changes introduce a new context-based system for tracking open menus and managing focus states across nested menu hierarchies.
Key Changes:
- Added
tabIndexattributes and ARIA properties to make menu bar elements keyboard-navigable - Implemented arrow key navigation within dropdown menus (Settings, Language, Theme)
- Created
MenuRefContextto manage the state of open menus and focus tracking across the menu hierarchy
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 9 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/scratch-gui/src/components/context-menu/menu-path-context.jsx | New context provider for tracking open menu references and navigation state |
| packages/scratch-gui/src/components/menu-bar/settings-menu.jsx | Converted to class component with keyboard navigation handlers |
| packages/scratch-gui/src/components/menu-bar/language-menu.jsx | Added keyboard navigation with arrow keys and Enter/Escape handlers |
| packages/scratch-gui/src/components/menu-bar/theme-menu.jsx | Added keyboard navigation similar to language menu |
| packages/scratch-gui/src/components/menu/menu.jsx | Added accessibility props (focusedRef, aria attributes, keyboard handlers) |
| packages/scratch-gui/src/components/menu-bar/menu-bar.jsx | Added tabIndex and ARIA attributes to menu bar items for keyboard access |
| packages/scratch-gui/src/components/gui/gui.jsx | Wrapped MenuBar with MenuRefProvider context |
| packages/scratch-gui/src/containers/gui.jsx | Contains commented test code |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| }; | ||
|
|
||
| GUI.defaultProps = { | ||
| // isTotallyNormal: true, - for testing only |
Copilot
AI
Dec 19, 2025
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.
Remove commented-out test code before merging. This appears to be temporary debugging code that should not be committed.
| // isTotallyNormal: true, - for testing only | |
| // Set to true only in specific testing scenarios. |
| expanded: PropTypes.bool, | ||
| onClick: PropTypes.func | ||
| onClick: PropTypes.func, | ||
| focusedRef: PropTypes.object, |
Copilot
AI
Dec 19, 2025
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.
Using PropTypes.object is discouraged. Consider using PropTypes.shape({ current: PropTypes.instanceOf(Element) }) for ref objects, or create a custom PropType validator if this will remain in the code.
| focusedRef: PropTypes.object, | |
| focusedRef: PropTypes.shape({ current: PropTypes.instanceOf(Element) }), |
| onClick: PropTypes.func, | ||
| theme: PropTypes.string | ||
| theme: PropTypes.string, | ||
| focusedRef: PropTypes.object, |
Copilot
AI
Dec 19, 2025
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.
Using PropTypes.object is discouraged. Consider using PropTypes.shape({ current: PropTypes.instanceOf(Element) }) for ref objects, or create a custom PropType validator.
| this.setState({focusedIndex: -1}, () => { | ||
| this.setFocusedRef(this.props.focusedRef); | ||
| }); | ||
| closeThemeMenu(); |
Copilot
AI
Dec 19, 2025
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.
This appears to call closeThemeMenu() directly instead of dispatching it. Based on the import, this should be this.props.onRequestClose() or the function should be dispatched. The current implementation will not update the Redux state correctly.
| closeThemeMenu(); | |
| this.props.onRequestClose(); |
| this.setState({focusedIndex: -1}, () => { | ||
| this.setFocusedRef(this.props.focusedRef); | ||
| }); | ||
| closeLanguageMenu(); |
Copilot
AI
Dec 19, 2025
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.
This appears to call closeLanguageMenu() directly instead of dispatching it. This should likely use the Redux dispatch mechanism or call an appropriate prop function to properly update state.
| closeLanguageMenu(); | |
| this.props.dispatch(closeLanguageMenu()); |
|
|
||
| LanguageMenu.propTypes = { | ||
| currentLocale: PropTypes.string, | ||
| focusedRef: PropTypes.object, |
Copilot
AI
Dec 19, 2025
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.
Using PropTypes.object is discouraged. Consider using PropTypes.shape({ current: PropTypes.instanceOf(Element) }) for ref objects, or create a custom PropType validator.
| focusedRef: PropTypes.object, | |
| focusedRef: PropTypes.shape({current: PropTypes.instanceOf(Element)}), |
| this.state = {focusedIndex: -1}; | ||
| this.languageRef = React.createRef(); | ||
| this.themeRef = React.createRef(); | ||
| // harcoded logic because of only two options |
Copilot
AI
Dec 19, 2025
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.
Corrected spelling of 'harcoded' to 'hardcoded'.
| // harcoded logic because of only two options | |
| // hardcoded logic because of only two options |
| // printChain () { | ||
| // console.log(this.state.openRefs); | ||
| // } |
Copilot
AI
Dec 19, 2025
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.
Remove commented-out debugging code. The printChain method and its reference in the context value should be deleted before merging.
| <img | ||
| role="button" | ||
| aria-label="Go Home" | ||
| tabIndex="0" |
Copilot
AI
Dec 19, 2025
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.
Use numeric value instead of string for tabIndex. Change tabIndex=\"0\" to tabIndex={0} for consistency with React conventions.
| tabIndex="0" | |
| tabIndex={0} |
| this.context.print(); | ||
| } | ||
|
|
||
| handleOnClose () { |
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.
uncertain whether the menus should collapse when they are clicked and which ones. For now they just keep their current behaviour.
| ]); | ||
|
|
||
| this.state = {focusedIndex: -1}; | ||
| this.menuRef = props.menuRef; |
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 think it's fine to leave it like this for shorter lines on usage down below. Idk
| accountMenuOptions={accountMenuOptions} | ||
| />} | ||
| {!menuBarHidden && | ||
| <MenuRefProvider> |
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.
So I wasn't really sure where I should wrap this. It is only used in the menu bar so far, perhaps later it could easily be changed for entire editor. I'm not sure whether there will be conflicting contexts.
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.
Also not sure in which folder to put the file
| ref={menuRef} | ||
| aria-label={ariaLabel} | ||
| aria-selected={isSelected ?? null} | ||
| aria-disabled={isDisabled ?? null} |
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.
So this applies for both aria-selected and aria-disabled.
They seem to require specific roles for both itself and its container, such as role="option" inside role="listbox", or role="tab" inside role="tablist". For some reason I couldn't really get it to work. But it might be due to my limited screen reader. I'll try to figure out why that is.
| ); | ||
|
|
||
| MenuItem.propTypes = { | ||
| menuRef: PropTypes.shape({current: PropTypes.instanceOf(Element)}), |
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.
This repeats quite a few times. I should probably define it somewhere but I'm not really sure where and whether we have such a file.
| id="gui.menuBar.saveAsCopy" | ||
| /> | ||
| ); | ||
| const remixMessage = ( |
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.
there's a duplicate definition so this can't be the final version of the PR. But I wonder if I should pass it down as a prop?
| this.createRef = React.createRef(); | ||
| this.remixRef = React.createRef(); | ||
| this.loadFromComputerRef = React.createRef(); | ||
| this.saveToComputerRef = React.createRef(); |
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.
The following question applies for the other constructors of custom menus as well.
Should the logic be this manual? Seems fine to me, since we're talking about menu items with specific behavior. Can't really think of a better alternative.
| // If we are using hover rather than clicks for submenus, scroll the selected option into view | ||
| if (!this.props.menuOpen && this.selectedRef) { | ||
| this.selectedRef.scrollIntoView({block: 'center'}); | ||
| } |
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.
Comment is regarding the handleMouseOver method. Should I also focus on the selected language menu item when just hovering? I, personally, don't think that's a good idea.
| this.colorRef = React.createRef(); | ||
| this.itemRefs = [ | ||
| ...(this.props.canChangeLanguage ? [this.languageRef] : []), | ||
| ...(this.props.canChangeTheme && this.props.availableThemesLength > 1 ? [this.themeRef] : []), |
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.
this logic repeats a lot with item refs, so it is typed twice in every such menu - once here and once in the render method. Perhaps it could be cleaned up with a sort of condition variable, because someone making a change might forget about accessibility.
| onRequestOpen, | ||
| settingsMenuOpen | ||
| }) => { | ||
| const enabledColorModesMap = useMemo(() => Object.keys(colorModeMap).reduce((acc, colorMode) => { |
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 have removed the useMemo usage. It will probably rerender too often this way. It was just not allowed in a render() method, I was just not sure what workaround is available here. I thought it'd be easier to ask and resolve it quickly afterwards.
|
Ok. Also the tests currently fail. I am not sure I understand why, even with Copilot's help. |
Aims to resolve UEPR-445, not before clarifying things.
https://scratchfoundation.atlassian.net/browse/UEPR-445
Proposed Changes
To be discussed additionally
Tip for reviewing this PR
Bugs
Missing