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

feat: allow matching navigation hierarchies with side nav item #6583

Merged
merged 3 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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