From f43e26cb5d1f3f00070462a422f828aa9f6e5425 Mon Sep 17 00:00:00 2001 From: Tomi Virkki Date: Mon, 12 Feb 2024 16:15:28 +0200 Subject: [PATCH] feat: support reverse button collapsing order in menu-bar (#6048) --- .../flow/component/menubar/MenuBar.java | 24 +++++++++++++++++++ .../component/menubar/tests/MenuBarTest.java | 15 ++++++++++++ 2 files changed, 39 insertions(+) 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 4d135002e64..c7be92e21d0 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);