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

Conversation

anuj123upadhyay
Copy link

Description

This PR improves accessibility by making the mobile navigation toggle icon (navInteractionIcon) keyboard accessible.
Previously, the icon could only be toggled via mouse click. With this update, users can now navigate to the toggle using the Tab key and activate it using Enter or Space.

Validation

Screen.Recording.2025-07-02.at.12.24.09.PM.mov

Related Issues

Fixes #7895

Check List

  • [✅] I have read the Contributing Guidelines and made commit messages that follow the guideline.
  • [✅] I have run pnpm format to ensure the code follows the style guide.
  • [✅] I have run pnpm test to check if all tests are passing.
  • [✅] I have run pnpm build to check if the website builds without errors.

@Copilot Copilot AI review requested due to automatic review settings July 2, 2025 07:51
@anuj123upadhyay anuj123upadhyay requested a review from a team as a code owner July 2, 2025 07:51
Copy link

vercel bot commented Jul 2, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
nodejs-org ✅ Ready (Inspect) Visit Preview Jul 2, 2025 7:52am

Copy link
Contributor

@Copilot Copilot AI left a 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 enhances keyboard accessibility for the mobile navigation toggle by allowing it to receive focus and respond to Enter/Space keys.

  • Added tabIndex, aria-label, and onKeyDown handlers to the toggle label.
  • Ensured the toggle input is activated via keyboard events.
Comments suppressed due to low confidence (1)

packages/ui-components/Containers/NavBar/index.tsx:59

  • Add aria-expanded={isMenuOpen} and aria-controls="sidebarItemToggler" to communicate the toggle state and the controlled element to assistive technologies.
          aria-label={sidebarItemTogglerAriaLabel}

@@ -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.

Comment on lines +63 to +66
const input = document.getElementById(
'sidebarItemToggler'
) as HTMLInputElement;
input?.click(); // Triggers input toggle
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.

aria-label={sidebarItemTogglerAriaLabel}
onKeyDown={e => {
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.

Copy link
Member

@ovflowd ovflowd left a comment

Choose a reason for hiding this comment

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

In which circumstances will someone need to use the keyboard on a touch device such as a phone? Since this view is only rendered for small screens, supposedly touch? I feel we're trying to fix a non-existent issue.

I also don't think we should go the JavaScript route, this is 100% doable without JavaScript as @avivkeller mentioned. Check https://stackoverflow.com/questions/53753223/how-to-allow-for-users-to-keyboard-tab-over-and-select-invisible-checkboxes-with for example.

@ShubhamOulkar
Copy link
Contributor

I feel we're trying to fix a non-existent issue.

Dev 😃 issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

The toggle navigation menu button is not keyboard accessible
5 participants