Skip to content

Commit

Permalink
feat: add setTabNavigation / isTabNavigation to MenuBar (#6554)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcgueriaud1 authored Aug 20, 2024
1 parent ad8f784 commit f712143
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,28 @@ public boolean isReverseCollapseOrder() {
return getElement().getProperty("reverseCollapse", false);
}

/**
* Sets tab navigation for the menu bar.
*
* @param tabNavigation
* If {@code true}, the top-level menu items is traversable by
* tab instead of arrow keys (i.e. disabling roving tabindex)
*/
public void setTabNavigation(boolean tabNavigation) {
getElement().setProperty("tabNavigation", tabNavigation);
}

/**
* Gets whether the menu bar uses tab navigation.
*
* @return {@code true} if the top-level menu items is traversable by tab
* instead of arrow keys (i.e. disabling roving tabindex)
*
*/
public boolean isTabNavigation() {
return getElement().getProperty("tabNavigation", false);
}

/**
* Gets the internationalization object previously set for this component.
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,21 @@ public void setReverseCollapseOrder_isReverseCollapseOrder() {
menuBar.getElement().getProperty("reverseCollapse", false));
}

@Test
public void isTabNavigation() {
Assert.assertFalse(menuBar.isTabNavigation());
Assert.assertFalse(
menuBar.getElement().getProperty("tabNavigation", false));
}

@Test
public void setTabNavigation_isTabNavigation() {
menuBar.setTabNavigation(true);
Assert.assertTrue(menuBar.isTabNavigation());
Assert.assertTrue(
menuBar.getElement().getProperty("tabNavigation", false));
}

private void assertChildrenAndItems(MenuItem... expected) {
Object[] menuItems = menuBar.getChildren().toArray();
Assert.assertArrayEquals(expected, menuItems);
Expand Down

0 comments on commit f712143

Please sign in to comment.