Skip to content

Conversation

tcbegley
Copy link
Collaborator

@tcbegley tcbegley commented Nov 26, 2020

This PR enables NavLink to automatically detect active state based on the current URL. active can still be set to True or False to manually control whether the NavLink shows as active or not, or can be set to either "exact" or "partial" with the following properties

  • If active="exact" then the active styling will be applied if the current pathname exactly matches the href of the NavLink. For example, dbc.NavLink(..., href="/my-page") will automatically be active on /my-page but on no other page.
  • If active="partial" then the active styling will be applied if the current pathname starts with the href of the NavLink. For example, dbc.NavLink(..., href="/pets") is active on /pets, /pets/dogs, /pets/cats etc., but not on /random.

@tcbegley tcbegley requested a review from Jason-AM November 26, 2020 08:30
* "/my-page" but not "/my-page/other" or "/random"
* - dbc.NavLink(..., href="/my-page", active="partial") will be active on
* "/my-page" and "/my-page/other" but not "/random"
*/
Copy link
Contributor

Choose a reason for hiding this comment

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

Is is worth having an explanation of the format an href must take? From what I can see this doesn't account for someone using http://...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, this is a good call. I'll try to clarify the docstring / documentation.

@tcbegley tcbegley merged commit fcbd1e1 into master Dec 3, 2020
@tcbegley tcbegley deleted the active-navlinks branch December 3, 2020 07:35
This was referenced Dec 13, 2020
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.

2 participants