[Menu] NbMenu - Deselect all menu items when this.findItemByUrl() returns undefined
See original GitHub issueIssue type
I’m submitting a … (check one with “x”)
- bug report
- feature request
Issue description
Current behavior: When there are two NbMenu components active on a single page (for example, in the ngx-admin demo) and they both contain different NbMenuItems, both NbMenus will retain the .active class on the last NbMenuItem that was clicked, even if the router path does not match either of the active links.
Expected behavior: I see that the NbMenu component subscribes to router event changes, during which a pathMatch full or partial check is initiated by the selectFromUrl method. However, the selectUrlFrom method will only set the selected property to true if there is a match. In the case when there is no match, it should de-select any active links.
Steps to reproduce:
- Create two NbMenu components on a page, each being passed different NbMenuItem arrays.
- Click on a link from the first NbMenu component, verify that the router has navigated to the link and that the link has the .active class.
- Click on a link from the second NbMenu component, verify that the router has navigated to the link and both NbMenu components have .active classes on the links that were clicked.
Related code: N/A
Other information:
npm, node, OS, Browser
Node: 10.13.0
OS: macOS High Sierra
Browser: Chrome 72.0
Angular, Nebular
Angular: 6.0
Nebular: 2.0.2
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (4 by maintainers)
Top GitHub Comments
thanks a lot for that @m-mo ! @nnixaa this needs your input. do you think it would be ok to update this block here to do a reset of the selection, like:
I gave this a shot locally and it fixes the raised issue. But I am not sure if other scenarios would be affected or not
The problem seems to be that if no menuItem matches the URL it does nothing. It should set all to “not selected” and not only when some menuItem matches. It is a bad behavior.
In order not to overwrite the component my solution has been to create a menuItem (that is always the last in the array, because the selection is done with the first one that makes match) that always will make match and to have it hidden always (hidden: true).
However, this may not be useful in all cases. And it is clearly a stopgap