Skip to content

Commit

Permalink
feat: allow matching navigation hierarchies with side nav item (#6583)
Browse files Browse the repository at this point in the history
  • Loading branch information
sissbruecker authored Aug 29, 2024
1 parent 3607801 commit 3184d30
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,34 @@ public void setTarget(String target) {
}
}

/**
* Gets whether this item also matches nested paths / routes.
*
* @return true if this item also matches nested paths / routes, false
* otherwise
*/
public boolean isMatchNested() {
return getElement().getProperty("matchNested", false);
}

/**
* Sets whether to also match nested paths / routes. {@code false} by
* default.
* <p>
* When enabled, an item with the path {@code /path} is considered current
* when the browser URL is {@code /path}, {@code /path/child},
* {@code /path/child/grandchild}, etc.
* <p>
* Note that this only affects matching of the URLs path, not the base
* origin or query parameters.
*
* @param value
* true to also match nested paths / routes, false otherwise
*/
public void setMatchNested(boolean value) {
getElement().setProperty("matchNested", value);
}

/**
* @return true if this item should be ignored by the Vaadin router and
* behave like a regular anchor.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,24 @@ public void targetDefined_setToNull_noTarget() {
Assert.assertNull(sideNavItem.getTarget());
}

@Test
public void isMatchNested_falseByDefault() {
Assert.assertFalse(sideNavItem.isMatchNested());
}

@Test
public void setMatchNested_isMatchNested() {
sideNavItem.setMatchNested(true);
Assert.assertTrue(
sideNavItem.getElement().getProperty("matchNested", false));
Assert.assertTrue(sideNavItem.isMatchNested());

sideNavItem.setMatchNested(false);
Assert.assertFalse(
sideNavItem.getElement().getProperty("matchNested", false));
Assert.assertFalse(sideNavItem.isMatchNested());
}

@Test
public void isRouterIgnore_falseByDefault() {
Assert.assertFalse(sideNavItem.isRouterIgnore());
Expand Down

0 comments on commit 3184d30

Please sign in to comment.