question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Menu] NbMenu - Deselect all menu items when this.findItemByUrl() returns undefined

See original GitHub issue

Issue 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:

  1. Create two NbMenu components on a page, each being passed different NbMenuItem arrays.
  2. 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.
  3. 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:open
  • Created 5 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
aefoxcommented, Mar 6, 2019

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:

if (selectedItem) {
  this.selectItem(selectedItem, items, collapseOther, tag);
} else {
  this.resetSelection(items);
}

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

0reactions
JudithMMolinacommented, Sep 16, 2021

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Select menu item link returns undefined - Stack Overflow
The action that I want is to change the video to their respective item when keyboard "enter" but it returns me an error...
Read more >
Menu Angular UI Component - Nebular - GitHub Pages
NbMenuComponent. Vertical menu component. Accepts a list of menu items and renders them accordingly. Supports multi-level menus. Basic example. Showcase.
Read more >
Menu - How to prevent deselection of item - DevExpress Support
DevExpress Support Team: CLONED FROM T735471: Menu deselect item, Remove focus state] Hello I've two questions related to devextreme menu.
Read more >
Angular6 issues and how to fix | GitAnswer
nebular nbMenu - Deselect all menu items when this.findItemByUrl() returns undefined ... nebular aCL with sidebar menu ...
Read more >
(request) system tray blended into the bottom bar - NsCDE/NsCDE
1, 2019-12-26, 2022-02-09. [Menu] NbMenu - Deselect all menu items when this.findItemByUrl() returns undefined, 6, 2019-03-05, 2022-08-16.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found