diff --git a/vaadin-side-nav-flow-parent/vaadin-side-nav-flow/src/main/java/com/vaadin/flow/component/sidenav/SideNavItem.java b/vaadin-side-nav-flow-parent/vaadin-side-nav-flow/src/main/java/com/vaadin/flow/component/sidenav/SideNavItem.java index 1650da66a20..7d564c9db2c 100644 --- a/vaadin-side-nav-flow-parent/vaadin-side-nav-flow/src/main/java/com/vaadin/flow/component/sidenav/SideNavItem.java +++ b/vaadin-side-nav-flow-parent/vaadin-side-nav-flow/src/main/java/com/vaadin/flow/component/sidenav/SideNavItem.java @@ -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. + *

+ * 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. + *

+ * 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. diff --git a/vaadin-side-nav-flow-parent/vaadin-side-nav-flow/src/test/java/com/vaadin/flow/component/sidenav/tests/SideNavItemTest.java b/vaadin-side-nav-flow-parent/vaadin-side-nav-flow/src/test/java/com/vaadin/flow/component/sidenav/tests/SideNavItemTest.java index 81314ccce3d..b2a9924fb57 100644 --- a/vaadin-side-nav-flow-parent/vaadin-side-nav-flow/src/test/java/com/vaadin/flow/component/sidenav/tests/SideNavItemTest.java +++ b/vaadin-side-nav-flow-parent/vaadin-side-nav-flow/src/test/java/com/vaadin/flow/component/sidenav/tests/SideNavItemTest.java @@ -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());