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

Active NavLinks #482

Merged
merged 3 commits into from
Dec 3, 2020
Merged

Active NavLinks #482

merged 3 commits into from
Dec 3, 2020

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
* - dbc.NavLink(..., href="/my-page", active="exact") will be active on
* "/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
Collaborator

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
Development

Successfully merging this pull request may close these issues.

2 participants