Skip to content

Conversation

@Srijatalamarla
Copy link
Contributor

Proposed change

Resolves #2035

Before fix:
Screenshot 2025-08-17 094740

After fix:
Screenshot 2025-08-17 094757

Checklist

  • I've read and followed the contributing guidelines.
  • I've run make check-test locally; all checks and tests passed.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 17, 2025

Summary by CodeRabbit

  • Style

    • Updated inactive submenu items in the navigation dropdown to use medium font weight for improved readability while keeping active item styling unchanged.
  • Tests

    • Added unit tests to confirm active styling applies only to the matching submenu item.
    • Verified non-active submenu items use the updated medium font weight and appropriate color styling.

Walkthrough

Adjusted inactive submenu item styling to include font-medium in frontend/src/components/NavDropDown.tsx; added two unit tests verifying active vs. inactive submenu item classes in frontend/__tests__/unit/components/NavDropDown.test.tsx. No public API changes.

Changes

Cohort / File(s) Summary
Dropdown submenu styling
frontend/src/components/NavDropDown.tsx
Updated non-active submenu item class string to include font-medium (changed weight for inactive items); active branch unchanged.
Unit tests for NavDropDown
frontend/__tests__/unit/components/NavDropDown.test.tsx
Added two async tests: one asserting active submenu link has font-bold text-white, another asserting other submenu links have font-medium text-slate-600.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Assessment against linked issues

Objective Addressed Explanation
Fix bold text on Community dropdown select (#2035)

Assessment against linked issues: Out-of-scope changes

(none)

Possibly related PRs

Suggested labels

frontend-tests

Suggested reviewers

  • arkid15r
  • kasya

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🔭 Outside diff range comments (1)
frontend/src/components/NavDropDown.tsx (1)

82-89: Don’t prevent default on Enter for submenu links; it can block navigation

Preventing default on Enter for can cancel the implicit click in some browsers, harming keyboard navigation. Let Enter pass through; optionally support Space by translating it into a click.

Apply this diff:

-              onKeyDown={(e) => {
-                if (e.key === 'Enter' || e.key === ' ') {
-                  e.preventDefault()
-                  setIsOpen(false)
-                } else if (e.key === 'Escape') {
-                  setIsOpen(false)
-                }
-              }}
+              onKeyDown={(e) => {
+                if (e.key === ' ') {
+                  // Support spacebar activation without breaking navigation
+                  e.preventDefault()
+                  e.currentTarget.click()
+                } else if (e.key === 'Escape') {
+                  e.preventDefault()
+                  setIsOpen(false)
+                }
+              }}
🧹 Nitpick comments (5)
frontend/src/components/NavDropDown.tsx (5)

79-79: Confirm weight choice: consider font-normal if “regular” weight is desired

If the intended look for inactive items is the default/regular weight (not medium), switch to font-normal to fully match prior styling on non-Community pages.

Apply if desired:

-                  : 'font-medium text-slate-600 hover:bg-slate-100 hover:text-slate-900 dark:text-slate-400 dark:hover:bg-slate-700 dark:hover:text-white'
+                  : 'font-normal text-slate-600 hover:bg-slate-100 hover:text-slate-900 dark:text-slate-400 dark:hover:bg-slate-700 dark:hover:text-white'

38-40: Prefer some() over map().includes() to avoid extra allocations and clarify intent

This avoids creating an intermediate array of hrefs each render and reads closer to the intent.

Apply this diff:

-        link.submenu.map((sub) => sub.href).includes(pathname) &&
+        link.submenu.some((sub) => sub.href === pathname) &&

15-15: Type the ref for safer DOM usage

Typing the ref prevents TS errors around .contains and improves editor IntelliSense.

Apply this diff:

-  const dropdownRef = useRef(null)
+  const dropdownRef = useRef<HTMLDivElement>(null)

20-24: Guard event.target with a Node check to satisfy TS and edge cases

EventTarget isn’t guaranteed to be a Node. Add a type guard before calling .contains.

Apply this diff:

-    function handleClickOutside(event: MouseEvent) {
-      if (dropdownRef.current && !dropdownRef.current.contains(event.target)) {
+    function handleClickOutside(event: MouseEvent) {
+      if (
+        dropdownRef.current &&
+        event.target instanceof Node &&
+        !dropdownRef.current.contains(event.target)
+      ) {
         setIsOpen(false)
       }
     }

73-73: Avoid using index as React key; prefer a stable identifier

Using href (or another unique field) avoids unnecessary re-mounts when the list changes.

Apply this diff:

-              key={idx}
+              key={submenu.href ?? String(idx)}
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between bb99e46 and a3db5b8.

📒 Files selected for processing (1)
  • frontend/src/components/NavDropDown.tsx (1 hunks)
🔇 Additional comments (1)
frontend/src/components/NavDropDown.tsx (1)

79-79: Fix correctly prevents inherited bold in submenu items

Adding font-medium on the inactive branch overrides the parent’s font-bold when on a submenu route. This directly addresses the reported issue.

@Srijatalamarla Srijatalamarla changed the title Fix/dropdown text Fix: Bold text on Community dropdown Aug 17, 2025
Copy link
Collaborator

@kasya kasya left a comment

Choose a reason for hiding this comment

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

This looks good! 👍🏼
Could you also add a couple of tests to check for styling in active/inactive state? Nothing crazy, just these two cases.

@Srijatalamarla
Copy link
Contributor Author

Sure! I'll add the tests soon. Thanks for the review!

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
frontend/__tests__/unit/components/NavDropDown.test.tsx (2)

132-148: Solid targeted test for active submenu styling; consider making it more robust

Two small improvements:

  • Use findByRole after opening the menu to avoid timing flakiness.
  • Add negative assertions to ensure inactive-only classes aren’t present on the active item.

Apply this diff:

 it('applies active styling to submenu item when pathname matches', async () => {
   const propsWithActiveSubmenu = {
     pathname: '/docs/getting-started',
     link: mockLink,
   }

   const user = userEvent.setup()
   render(<NavDropdown {...propsWithActiveSubmenu} />)

   const button = screen.getByRole('button')
   await user.click(button)

   //active
-  const gettingStartedLink = screen.getByRole('link', { name: /getting started/i })
-
-  expect(gettingStartedLink).toHaveClass('font-bold', 'text-white')
+  const gettingStartedLink = await screen.findByRole('link', { name: /getting started/i })
+  expect(gettingStartedLink).toHaveClass('font-bold', 'text-white')
+  expect(gettingStartedLink).not.toHaveClass('font-medium', 'text-slate-600')
 })

150-168: Great verification of sibling items; add negative assertions and await DOM updates

  • Use findByRole for submenu links post-toggle.
  • Assert that active-only classes are not applied to inactive items.

Apply this diff:

 it('does not apply active styling to other submenu items when one is active', async () => {
   const propsWithActiveSubmenu = {
     pathname: '/docs/getting-started',
     link: mockLink,
   }

   const user = userEvent.setup()
   render(<NavDropdown {...propsWithActiveSubmenu} />)

   const button = screen.getByRole('button')
   await user.click(button)

   //inactive
-  const apiReferenceLink = screen.getByRole('link', { name: /api reference/i })
-  const examplesLink = screen.getByRole('link', { name: /examples/i })
-
-  expect(apiReferenceLink).toHaveClass('font-medium', 'text-slate-600')
-  expect(examplesLink).toHaveClass('font-medium', 'text-slate-600')
+  const apiReferenceLink = await screen.findByRole('link', { name: /api reference/i })
+  const examplesLink = await screen.findByRole('link', { name: /examples/i })
+
+  expect(apiReferenceLink).toHaveClass('font-medium', 'text-slate-600')
+  expect(examplesLink).toHaveClass('font-medium', 'text-slate-600')
+  expect(apiReferenceLink).not.toHaveClass('font-bold', 'text-white')
+  expect(examplesLink).not.toHaveClass('font-bold', 'text-white')
 })
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between a3db5b8 and 0cad90b.

📒 Files selected for processing (1)
  • frontend/__tests__/unit/components/NavDropDown.test.tsx (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
frontend/__tests__/unit/components/NavDropDown.test.tsx (2)
frontend/src/wrappers/testUtil.tsx (1)
  • render (14-14)
frontend/src/components/NavDropDown.tsx (1)
  • NavDropdown (13-98)
🔇 Additional comments (1)
frontend/__tests__/unit/components/NavDropDown.test.tsx (1)

132-168: These tests capture the original bug and the intended fix precisely

They validate that only the active submenu item is bolded and siblings remain medium-weight, matching the updated class logic. Nice addition to prevent regression.

@sonarqubecloud
Copy link

Copy link
Collaborator

@kasya kasya left a comment

Choose a reason for hiding this comment

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

Nice work! 👍🏼

@kasya kasya added this pull request to the merge queue Aug 20, 2025
Merged via the queue into OWASP:main with commit 74c8e91 Aug 20, 2025
25 checks passed
@Srijatalamarla Srijatalamarla deleted the fix/dropdown-text branch September 3, 2025 15:57
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.

Fix bold text on Community dropdown select

2 participants