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

collapseOnSelect will not collapse, if href prop of Nav.Link is missing #6654

Closed
3 tasks done
apepper opened this issue Jul 10, 2023 · 4 comments
Closed
3 tasks done
Labels

Comments

@apepper
Copy link

apepper commented Jul 10, 2023

Prerequisites

Describe the bug

collapseOnSelect does not have an affect on Navbar, if the Nav.Link has no href prop.

Expected behavior

The navigation dropdown should close on click.

To Reproduce

  1. Have a Navbar with the prop collapseOnSelect
  2. Inside declare a Nav.Link, but without a href prop.
  3. Now click on the hamburger menu - the navigation dropdown menu opens.
  4. Now click on the Nav.Link (in the minimal example the "Link" link")

It should not close the navigation dropdown menu. Instead it stays open. If the Nav.Link has a href prop all is working fine.

Reproducible Example

https://stackblitz.com/edit/stackblitz-starters-79mzqy?file=src%2FApp.tsx

What browser(s) are you seeing the problem on?

Chrome

What version of React-Bootstrap are you using?

2.8.0

What version of Bootstrap are you using?

5.3.0

Additional context

This bug becomes annoying, if one us using Nav.Link with the as property with a component, that does not need the href prop.

@apepper apepper added the bug label Jul 10, 2023
apepper added a commit to Scrivito/scrivito-portal-app that referenced this issue Jul 10, 2023
@kyletsang
Copy link
Member

Can you try passing the eventKey prop to the NavLink?

https://react-bootstrap.github.io/docs/components/navs#navlink

@apepper
Copy link
Author

apepper commented Jul 11, 2023

Can you try passing the eventKey prop to the NavLink?

With the eventKey it's working. Is this more or less a required property? If so I would recommend to update the example code e.g. on https://react-bootstrap.github.io/docs/components/navbar/.

apepper added a commit to Scrivito/scrivito-portal-app that referenced this issue Jul 11, 2023
As suggested in react-bootstrap/react-bootstrap#6654 (comment) one should use the "eventKey" prop.
@kyletsang
Copy link
Member

It's used as an identifier if you don't want to pass a href:
https://github.com/react-restart/ui/blob/44dc346744b37c33bd0d0309e5cd827751fce9c4/src/SelectableContext.tsx#L10

The docs are lacking in this area and should be updated

@apepper
Copy link
Author

apepper commented Jul 12, 2023

Great, thank @kyletsang for pointing me in the right direction!

@apepper apepper closed this as completed Jul 12, 2023
kyletsang added a commit that referenced this issue Jun 12, 2024
* Update Navbar.tsx

Add note to `collapseOnSelect` based on feedback in #6654

* Update Navbar.tsx

* Update NavLink.tsx

* Update src/Navbar.tsx

Co-authored-by: Kyle Tsang <6854874+kyletsang@users.noreply.github.com>

---------

Co-authored-by: Kyle Tsang <6854874+kyletsang@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants