Skip to content

Improve header accessibility and keyboard navigation support. Resolves #4804#4935

Open
Divyateja2709 wants to merge 2 commits into
OWASP:mainfrom
Divyateja2709:feature/navbar-theme-fix
Open

Improve header accessibility and keyboard navigation support. Resolves #4804#4935
Divyateja2709 wants to merge 2 commits into
OWASP:mainfrom
Divyateja2709:feature/navbar-theme-fix

Conversation

@Divyateja2709

@Divyateja2709 Divyateja2709 commented Jun 16, 2026

Copy link
Copy Markdown

hi @arkid15r and @kasya

Resolves #4804

This PR improves header accessibility and keyboard navigation support for OWASP Nest. The changes include:

  1. Skip-to-main content link (layout.tsx): Added a keyboard-accessible "Skip to main content" link at the top of the page, visible only on focus. Added id="main" to the <main> element as the anchor target.

  2. Mobile menu ARIA attributes (Header.tsx): Added aria-expanded and aria-controls="mobile-navigation" to the menu toggle button. Added role="navigation", id="mobile-navigation", and aria-hidden to the mobile navigation panel. The toggle label dynamically changes between "Open main menu" and "Close main menu" based on state.

  3. Focus management (Header.tsx): When the mobile menu opens, focus moves to the first focusable element inside it. When the menu closes (via button, Escape, or outside click), focus is restored to the toggle button.

  4. Escape-key support (Header.tsx): Pressing Escape now closes the mobile menu.

  5. Skip link styling (globals.css): Added .skip-link styles — hidden by default, visible on focus with high-contrast colors.

  6. Accessibility tests (Header.a11y.test.tsx): Added jest-axe tests verifying zero WCAG violations and correct ARIA attributes on the mobile menu toggle.

Checklist

  • Required: I followed the contributing workflow
  • Required: I verified that my code works as intended and resolves the issue as described
  • Required: I ran make check-test locally: all warnings addressed, tests passed
  • I used AI for code, documentation, tests, or communication related to this PR - For Documentation

@coderabbitai

coderabbitai Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Summary by CodeRabbit

  • New Features

    • Added skip to main content link for keyboard navigation.
    • Implemented keyboard support to close mobile menu with Escape key.
    • Enhanced focus management for mobile navigation menu.
    • Added ARIA attributes for improved screen reader support.
  • Tests

    • Added accessibility test suite for Header component.
  • Style

    • Added styling for keyboard skip link.

Walkthrough

Adds keyboard accessibility improvements to the frontend: a visually-hidden skip link in the global CSS and layout pointing to id="main", ARIA attributes (aria-expanded, aria-controls, aria-hidden) and focus management (capture, restore, Escape-key close) for the mobile navigation in Header, and a new jest-axe accessibility test suite covering those attributes.

Changes

Header Accessibility Improvements

Layer / File(s) Summary
Skip link: CSS and layout wiring
frontend/src/app/globals.css, frontend/src/app/layout.tsx
Adds .skip-link styles (off-screen by default, visible on focus/active) and renders the skip anchor in RootLayout targeting a new id="main" on the main content wrapper.
Header: ARIA attributes, focus management, and Escape key
frontend/src/components/Header.tsx
Imports useRef and adds a previousActiveElement ref; expands useEffect to register an Escape-key listener, capture the active element before opening the mobile menu, focus the first interactive element inside #mobile-navigation on open, and restore focus on close. Toggle button gains aria-expanded/aria-controls; mobile navigation container gains aria-hidden.
Accessibility test suite
frontend/__tests__/a11y/components/Header.a11y.test.tsx
Adds a Header accessibility describe block that renders the component, runs jest-axe, and asserts the mobile toggle button has aria-controls="mobile-navigation" and aria-expanded="false".

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • OWASP/Nest#1113: Directly modifies Header.tsx mobile menu toggle and close mechanics, overlapping with the mobile menu DOM structure changed here.
  • OWASP/Nest#1881: Adds Header unit tests covering mobile menu open/close and ARIA attributes, closely related to the new accessibility test coverage.
  • OWASP/Nest#3950: Adjusts focus-visible/outline styling on the mobile menu toggle, directly adjacent to the focus-management behavior added in this PR.

Suggested labels

frontend, frontend-tests

Suggested reviewers

  • arkid15r
  • kasya
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: improving header accessibility and keyboard navigation support, which aligns perfectly with the changeset.
Description check ✅ Passed The description comprehensively explains all changes across multiple files and directly relates to the changeset, providing clear context for the accessibility improvements.
Linked Issues check ✅ Passed All requirements from issue #4804 are met: skip-to-main link [layout.tsx], ARIA attributes and focus management [Header.tsx], Escape-key support [Header.tsx], skip-link styling [globals.css], and jest-axe tests [Header.a11y.test.tsx].
Out of Scope Changes check ✅ Passed All changes directly address the linked issue requirements; no out-of-scope modifications detected in the file alterations.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 Biome (2.5.0)
frontend/src/app/globals.css

File contains syntax errors that prevent linting: Line 3: Tailwind-specific syntax is disabled.; Line 17: Tailwind-specific syntax is disabled.; Line 304: Tailwind-specific syntax is disabled.; Line 481: Tailwind-specific syntax is disabled.; Line 485: Tailwind-specific syntax is disabled.; Line 486: Tailwind-specific syntax is disabled.; Line 487: Tailwind-specific syntax is disabled.; Line 492: Tailwind-specific syntax is disabled.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@sonarqubecloud

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@frontend/src/components/Header.tsx`:
- Around line 173-181: Add the id attribute "mobile-menu-toggle" to the Button
component with onPress={toggleMobileMenu}. The focus-restore logic references
this id as a fallback when the previously focused element is no longer available
in the DOM, so without it, focus restoration will fail when the
originally-focused element becomes unavailable.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: a564c413-6e4f-4b30-b885-20542c8efb8f

📥 Commits

Reviewing files that changed from the base of the PR and between 39d2336 and b542903.

📒 Files selected for processing (4)
  • frontend/__tests__/a11y/components/Header.a11y.test.tsx
  • frontend/src/app/globals.css
  • frontend/src/app/layout.tsx
  • frontend/src/components/Header.tsx

Comment on lines 173 to 181
<Button
onPress={toggleMobileMenu}
aria-expanded={mobileMenuOpen}
aria-controls="mobile-navigation"
className="flex h-11 w-11 items-center justify-center rounded-lg bg-transparent text-slate-300 hover:bg-transparent hover:text-slate-100 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-white"
>
<span className="sr-only">Open main menu</span>
<span className="sr-only">{mobileMenuOpen ? 'Close main menu' : 'Open main menu'}</span>
{mobileMenuOpen ? <FaTimes className="h-6 w-6" /> : <FaBars className="h-6 w-6" />}
</Button>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Add id="mobile-menu-toggle" to enable fallback focus restoration.

The focus-restore logic at line 74 falls back to document.getElementById('mobile-menu-toggle') when previousActiveElement.current is null, but the toggle button lacks this id attribute. If the originally-focused element becomes unavailable (e.g., removed from DOM), focus will be lost.

Proposed fix
           <Button
+            id="mobile-menu-toggle"
             onPress={toggleMobileMenu}
             aria-expanded={mobileMenuOpen}
             aria-controls="mobile-navigation"
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@frontend/src/components/Header.tsx` around lines 173 - 181, Add the id
attribute "mobile-menu-toggle" to the Button component with
onPress={toggleMobileMenu}. The focus-restore logic references this id as a
fallback when the previously focused element is no longer available in the DOM,
so without it, focus restoration will fail when the originally-focused element
becomes unavailable.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

2 issues found across 4 files

Confidence score: 3/5

  • In frontend/src/app/layout.tsx, the skip link points to a <main> element that isn’t focusable, so keyboard users may activate “skip to content” without actually landing in main content, weakening core navigation accessibility — make the target programmatically focusable (for example with tabIndex={-1}) and move focus there before merging.
  • In frontend/src/components/Header.tsx, the focus-restoration fallback targets a missing #mobile-menu-toggle, so when the menu closes focus can be lost or sent nowhere, creating a confusing keyboard/screen-reader flow — update the selector to an existing control (or use a ref-based fallback) and verify close/restore behavior before merging.
Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="frontend/src/app/layout.tsx">

<violation number="1" location="frontend/src/app/layout.tsx:83">
P1: Skip-to-content link target `<main>` is not focusable, so keyboard focus may not move to the main content after activation, defeating the skip link's purpose for keyboard users.</violation>
</file>

<file name="frontend/src/components/Header.tsx">

<violation number="1" location="frontend/src/components/Header.tsx:74">
P2: Focus restoration fallback references a non-existent `#mobile-menu-toggle` element</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

<Header isGitHubAuthEnabled={IS_GITHUB_AUTH_ENABLED} />
<BreadCrumbsWrapper />
<main className="flex flex-1 flex-col justify-center">{children}</main>
<main id="main" className="flex flex-1 flex-col justify-center">{children}</main>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1: Skip-to-content link target <main> is not focusable, so keyboard focus may not move to the main content after activation, defeating the skip link's purpose for keyboard users.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At frontend/src/app/layout.tsx, line 83:

<comment>Skip-to-content link target `<main>` is not focusable, so keyboard focus may not move to the main content after activation, defeating the skip link's purpose for keyboard users.</comment>

<file context>
@@ -71,13 +71,16 @@ export default function RootLayout({
               <Header isGitHubAuthEnabled={IS_GITHUB_AUTH_ENABLED} />
               <BreadCrumbsWrapper />
-              <main className="flex flex-1 flex-col justify-center">{children}</main>
+              <main id="main" className="flex flex-1 flex-col justify-center">{children}</main>
               <Footer />
               <ScrollToTop />
</file context>
Suggested change
<main id="main" className="flex flex-1 flex-col justify-center">{children}</main>
+ <main id="main" tabIndex={-1} className="flex flex-1 flex-col justify-center">{children}</main>

@@ -3,7 +3,7 @@ import { Button } from '@heroui/button'
import Image from 'next/image'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2: Focus restoration fallback references a non-existent #mobile-menu-toggle element

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At frontend/src/components/Header.tsx, line 74:

<comment>Focus restoration fallback references a non-existent `#mobile-menu-toggle` element</comment>

<file context>
@@ -46,12 +47,44 @@ export default function Header({ isGitHubAuthEnabled }: { readonly isGitHubAuthE
+        if (prev) {
+          prev.focus()
+        } else {
+          const toggle = document.getElementById('mobile-menu-toggle') as HTMLElement | null
+          toggle?.focus()
+        }
</file context>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve header accessibility and keyboard navigation support

1 participant