Skip to content

fix/The toggle navigation menu button is not keyboard accessible #7933

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions packages/ui-components/Containers/NavBar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,17 @@ const NavBar: FC<PropsWithChildren<NavbarProps>> = ({
className={style.sidebarItemTogglerLabel}
htmlFor="sidebarItemToggler"
role="button"
tabIndex={0}
Copy link
Preview

Copilot AI Jul 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using a native element instead of a with role="button" and tabIndex, so you get built-in keyboard support and proper semantics without custom handlers.

Copilot uses AI. Check for mistakes.

aria-label={sidebarItemTogglerAriaLabel}
onKeyDown={e => {
Copy link
Preview

Copilot AI Jul 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Switch to onKeyUp for handling the Space key, as using onKeyDown can trigger the action before the default spacebar scroll prevention is handled by the browser.

Suggested change
onKeyDown={e => {
onKeyUp={e => {

Copilot uses AI. Check for mistakes.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need an onKeyDown? It worked fine without one

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

onKeyDown will open the navInteractionIcon by pressing enter or space when the navInteractionIcon is in focused state.
like displayed in the video provided above.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you want me to add or remove something then please let me know.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't have an onClick handler, so I don't think we need an onKeyDown handler, is there a way to do this without?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't think so as we have to mimic the click event by pressing tab and enter on the navInteractionIcon,
if you can suggest , please let me know i am ready to for that.

if (e.key === 'Enter' || e.key === ' ') {
e.preventDefault();
const input = document.getElementById(
'sidebarItemToggler'
) as HTMLInputElement;
input?.click(); // Triggers input toggle
Comment on lines +63 to +66
Copy link
Preview

Copilot AI Jul 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than querying the DOM directly with getElementById, use a React ref on the input to avoid repeated lookups and improve maintainability.

Suggested change
const input = document.getElementById(
'sidebarItemToggler'
) as HTMLInputElement;
input?.click(); // Triggers input toggle
sidebarItemTogglerRef.current?.click(); // Triggers input toggle

Copilot uses AI. Check for mistakes.

}
}}
>
{navInteractionIcons[isMenuOpen ? 'close' : 'show']}
</Label.Root>
Expand Down