diff --git a/vaadin-menu-bar-flow-parent/vaadin-menu-bar-flow/src/main/java/com/vaadin/flow/component/menubar/MenuBar.java b/vaadin-menu-bar-flow-parent/vaadin-menu-bar-flow/src/main/java/com/vaadin/flow/component/menubar/MenuBar.java index dbbbf0d11b0..ea1d6fd9bef 100644 --- a/vaadin-menu-bar-flow-parent/vaadin-menu-bar-flow/src/main/java/com/vaadin/flow/component/menubar/MenuBar.java +++ b/vaadin-menu-bar-flow-parent/vaadin-menu-bar-flow/src/main/java/com/vaadin/flow/component/menubar/MenuBar.java @@ -387,6 +387,30 @@ public void removeThemeVariants(MenuBarVariant... variants) { .collect(Collectors.toList())); } + /** + * Sets reverse collapse order for the menu bar. + * + * @param reverseCollapseOrder + * If {@code true}, the buttons will be collapsed into the + * overflow menu starting from the "start" end of the bar instead + * of the "end". + */ + public void setReverseCollapseOrder(boolean reverseCollapseOrder) { + getElement().setProperty("reverseCollapse", reverseCollapseOrder); + } + + /** + * Gets whether the menu bar uses reverse collapse order. + * + * @return {@code true} if the buttons will be collapsed into the overflow + * menu starting from the "start" end of the bar instead of the + * "end". + * + */ + public boolean isReverseCollapseOrder() { + return getElement().getProperty("reverseCollapse", false); + } + /** * Gets the internationalization object previously set for this component. *
diff --git a/vaadin-menu-bar-flow-parent/vaadin-menu-bar-flow/src/test/java/com/vaadin/flow/component/menubar/tests/MenuBarTest.java b/vaadin-menu-bar-flow-parent/vaadin-menu-bar-flow/src/test/java/com/vaadin/flow/component/menubar/tests/MenuBarTest.java index 1b19cb9b1c9..48edc06e677 100644 --- a/vaadin-menu-bar-flow-parent/vaadin-menu-bar-flow/src/test/java/com/vaadin/flow/component/menubar/tests/MenuBarTest.java +++ b/vaadin-menu-bar-flow-parent/vaadin-menu-bar-flow/src/test/java/com/vaadin/flow/component/menubar/tests/MenuBarTest.java @@ -85,6 +85,21 @@ public void setOpenOnHover_isOpenOnHover() { Assert.assertTrue(menuBar.isOpenOnHover()); } + @Test + public void isReverseCollapseOrder() { + Assert.assertFalse(menuBar.isReverseCollapseOrder()); + Assert.assertFalse( + menuBar.getElement().getProperty("reverseCollapse", false)); + } + + @Test + public void setReverseCollapseOrder_isReverseCollapseOrder() { + menuBar.setReverseCollapseOrder(true); + Assert.assertTrue(menuBar.isReverseCollapseOrder()); + Assert.assertTrue( + menuBar.getElement().getProperty("reverseCollapse", false)); + } + private void assertChildrenAndItems(MenuItem... expected) { Object[] menuItems = menuBar.getChildren().toArray(); Assert.assertArrayEquals(expected, menuItems);