Skip to content
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

Multiple Tabs Marked as Active in Navigation Bar When Switching Between Tabs #9637

Open
Tracked by #9945
JavidSumra opened this issue Jan 1, 2025 · 9 comments · May be fixed by #9920
Open
Tracked by #9945

Multiple Tabs Marked as Active in Navigation Bar When Switching Between Tabs #9637

JavidSumra opened this issue Jan 1, 2025 · 9 comments · May be fixed by #9920

Comments

@JavidSumra
Copy link
Contributor

JavidSumra commented Jan 1, 2025

Bug Description:
When navigating between tabs in the navigation bar, multiple tabs are displayed as active simultaneously, instead of only highlighting the currently selected tab.

Steps to Reproduce:

  1. Navigate to the Facility Page.
  2. Click on Users and then switch to Schedule.
  3. Observe the issue where multiple tabs are marked as active.

Expected Behavior:
Only the currently active tab should be highlighted in the navigation bar.

Similar issues is occurring in the organisation page

Screenshots:
Image

Desktop (please complete the following information):

  • OS: Ubuntu
  • Browser Firefox
  • Version 133.0.3 (64-bit)
@saikiranpatil
Copy link

if this issue is available, i would like to work on this

@bodhish
Copy link
Member

bodhish commented Jan 1, 2025

@saikiranpatil do you sugget how you are planning to fix the issue.

@JavidSumra
Copy link
Contributor Author

JavidSumra commented Jan 2, 2025

@saikiranpatil do you sugget how you are planning to fix the issue.

@bodhish I'm working on it 😀
cc @saikiranpatil

@piyushyadav0191
Copy link

This issue is not assigned to anyone yet! Can you assign it to me @bodhish

@bodhish
Copy link
Member

bodhish commented Jan 2, 2025

I will not assign unless you explain how you are planing to solve it.

@manmeetnagii
Copy link
Contributor

I will not assign unless you explain how you are planing to solve it.

@bodhish the issue is related to activeClass and exactActiveClass attributes of ActiveLink component of raviger's package present in src/components/ui/sidebar/nav-main.tsx.

  <ActiveLink 
      href={link.url}
      activeClass="bg-white text-green-700 shadow"
      exactActiveClass="bg-white text-green-700 shadow"
  >
          {link.icon && <CareIcon icon={link.icon as IconName} />}
          <span className="group-data-[collapsible=icon]:hidden">
             {link.name}
          </span>
  </ActiveLink>

The uses of both attributes are as follow -

  1. ActiveClass: If the link.url matches the start of the route path this will be applied.
  2. exactActiveClass: If the link.url matches the route path exactly this will be applied.

Combining both will create a conflict between the matching of the routes, which is causing this issue. Also, the route of the resource page begins with '/resource' and the route of other pages begins with '/facility'. If a link.url matches both the start and the exact current path, both activeClass and exactActiveClass are applied.

Proposed Solution

We can change the path of resource page as '/facility/resource' or active the activeClass attribute only for '/resource' route. Below is the fixed version. Let me know if I can raise a PR for this if not done by anyone 😊

Screen.Recording.2025-01-03.055308.mp4

@github-actions github-actions bot added needs-triage question Further information is requested labels Jan 3, 2025
@JavidSumra
Copy link
Contributor Author

I will not assign unless you explain how you are planing to solve it.

@bodhish already found the root cause and working on it I'm solving it using useActiveLink hook as @manmeetnagii said it's related to activeClass and exactActiveClass.

@bodhish
Copy link
Member

bodhish commented Jan 3, 2025

@JavidSumra the fix doesn't work.

Also @manmeetnagii the solution you suggested will not work.

@rithviknishad rithviknishad marked this as a duplicate of #9709 Jan 3, 2025
@rajku-dev
Copy link
Contributor

rajku-dev commented Jan 3, 2025

@bodhish Sir, I have implemented a solution

  • stores link.name in nav-main component state which only changes when user clicks on some other navlink
  • active class is given to the navlink which is stored in state

@nihal467 nihal467 added this to the Palliative Care Release milestone Jan 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment