SideNav highlighter Problem

I’ve a subNavItem and when I click that, it is highlighted which is good. But when I directly hit the subNavItem address in the URL, it is not. I do not see the parent also getting highlighted. Is this a bug ?
image.png

image.png

image.png

it happens only for the subNavItem

It looks like it might be highlighted, but it’s not visible because the parent item is collapsed.

is it the expected behavior ?

I thought the parent will expand automatically

In the business app, it is how it is

https://labs.vaadin.com/business/accountants

That’s the current behavior and I don’t know of any feature request saying something different

Any quick fix to expand the parent ?

  • add a AfternavigationListener to the nav item
  • check if it has a parent → if yes → toggle parent if not opened

I tried something like this ``` @Override
public void afterNavigation(AfterNavigationEvent afterNavigationEvent) {
log.debug(“I’m here”,afterNavigationEvent.getLocation().getPath());

    nav.getItems().stream().filter(sideNavItem ->
            sideNavItem.getPath().equals(afterNavigationEvent.getLocation().getPath()))
            .findFirst()
            .ifPresent(sideNavItem -> {
                sideNavItem.setVisible(true);
                sideNavItem.setExpanded(true);
            });
}``` but no luck

I think you need to get the parent, which will not equal the path.
Debug to see if sideNavItem.getParent() returns a SideNavItem, if it does, use that - expand it.
If it doesn’t, you can modify your filter to be something like this.

nav.getItems().stream().filter(sideNavItem ->
afterNavigationEvent.getLocation().getPath()).contains(sideNavItem.getPath()))

sideNavItem.getParent() returns a Component

SideNavItem extends Component, did you debug or look at the API?

I saw this
image.png

and then tried this

Yeah, that’s the API. Do you know how to run in debug mode?
You can of course just test by logging messages as well.

.ifPresent(sideNavItem -> {
    if (sideNavItem.getParent().isPresent()) {
        log.warn("there is a parent");
        boolean isParentASideNavMenu = sideNavItem.getParent().get() instanceof SideNavItem;
        log.warn("is the parent a side nav menu item? " + isParentASideNavMenu);
        if (isParentASideNavMenu) {
            SideNavItem parent = (SideNavItem) sideNavItem.getParent().get();
            parent.setExpanded(true);
        }
    } else {
        log.warn("there is no parent");
    }
});

this method itself is not getting executed
image.png