Class MenuBar

java.lang.Object
com.vaadin.flow.component.Component
com.vaadin.flow.component.menubar.MenuBar
All Implemented Interfaces:
com.vaadin.flow.component.AttachNotifier, HasMenuItems, com.vaadin.flow.component.DetachNotifier, com.vaadin.flow.component.HasElement, com.vaadin.flow.component.HasEnabled, com.vaadin.flow.component.HasSize, com.vaadin.flow.component.HasStyle, com.vaadin.flow.component.HasTheme, HasThemeVariant<MenuBarVariant>, Serializable

@Tag("vaadin-menu-bar") @JsModule("./menubarConnector.js") @JsModule("@vaadin/menu-bar/src/vaadin-menu-bar.js") @JsModule("@vaadin/tooltip/src/vaadin-tooltip.js") @NpmPackage(value="@vaadin/menu-bar",version="25.0.0-alpha16") @NpmPackage(value="@vaadin/tooltip",version="25.0.0-alpha16") public class MenuBar extends com.vaadin.flow.component.Component implements com.vaadin.flow.component.HasEnabled, HasMenuItems, com.vaadin.flow.component.HasSize, com.vaadin.flow.component.HasStyle, HasThemeVariant<MenuBarVariant>
Menu Bar is a horizontal button bar with hierarchical drop-down menus. Menu items can either trigger an action, open a menu, or work as a toggle.
Author:
Vaadin Ltd
See Also:
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    The internationalization properties for MenuBar
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates an empty menu bar component.
  • Method Summary

    Modifier and Type
    Method
    Description
    addItem(com.vaadin.flow.component.Component component)
    Creates a new MenuItem component and adds it to the root level of this menu bar.
    addItem(com.vaadin.flow.component.Component component, com.vaadin.flow.component.ComponentEventListener<com.vaadin.flow.component.ClickEvent<MenuItem>> clickListener)
    Creates a new MenuItem component with the provided click listener and adds it to the root level of this menu bar.
    addItem(com.vaadin.flow.component.Component component, String tooltipText)
    Creates a new MenuItem component with the provided tooltip text and adds it to the root level of this menu bar.
    addItem(com.vaadin.flow.component.Component component, String tooltipText, com.vaadin.flow.component.ComponentEventListener<com.vaadin.flow.component.ClickEvent<MenuItem>> clickListener)
    Creates a new MenuItem component with the provided click listener and the tooltip text and adds it to the root level of this menu bar.
    Creates a new MenuItem component with the provided text content and adds it to the root level of this menu bar.
    addItem(String text, com.vaadin.flow.component.ComponentEventListener<com.vaadin.flow.component.ClickEvent<MenuItem>> clickListener)
    Creates a new MenuItem component with the provided text content and click listener and adds it to the root level of this menu bar.
    addItem(String text, String tooltipText)
    Creates a new MenuItem component with the provided text content and the tooltip text and adds it to the root level of this menu bar.
    addItem(String text, String tooltipText, com.vaadin.flow.component.ComponentEventListener<com.vaadin.flow.component.ClickEvent<MenuItem>> clickListener)
    Creates a new MenuItem component with the provided text content and the tooltip text and click listener and adds it to the root level of this menu bar.
    void
    Closes the current submenu.
    Stream<com.vaadin.flow.component.Component>
    Gets the child components of this menu bar.
    Gets the internationalization object previously set for this component.
    Gets the MenuItem components added to the root level of the menu bar.
    boolean
    Gets whether the sub menus open by clicking or hovering on the root level buttons.
    boolean
    Gets whether the menu bar uses reverse collapse order.
    boolean
    Gets whether the menu bar uses tab navigation.
    protected void
    onAttach(com.vaadin.flow.component.AttachEvent attachEvent)
     
    void
    remove(MenuItem... items)
    Removes the given item components from this menu bar.
    void
    Removes all item components from this menu bar.
    void
    Sets the internationalization object for this component.
    void
    setOpenOnHover(boolean openOnHover)
    Sets the event which opens the sub menus of the root level buttons.
    void
    setReverseCollapseOrder(boolean reverseCollapseOrder)
    Sets reverse collapse order for the menu bar.
    void
    setTabNavigation(boolean tabNavigation)
    Sets tab navigation for the menu bar.
    void
    setTooltipText(MenuItem item, String tooltipText)
    Sets the tooltip text for the given MenuItem.

    Methods inherited from class com.vaadin.flow.component.Component

    addListener, findAncestor, fireEvent, from, get, getElement, getEventBus, getId, getListeners, getLocale, getParent, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getUI, hasListener, isAttached, isTemplateMapped, isVisible, onDetach, onEnabledStateChanged, removeFromParent, scrollIntoView, scrollIntoView, set, setElement, setId, setVisible

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface com.vaadin.flow.component.AttachNotifier

    addAttachListener

    Methods inherited from interface com.vaadin.flow.component.DetachNotifier

    addDetachListener

    Methods inherited from interface com.vaadin.flow.component.HasElement

    getElement

    Methods inherited from interface com.vaadin.flow.component.HasEnabled

    isEnabled, setEnabled

    Methods inherited from interface com.vaadin.flow.component.HasSize

    getHeight, getHeightUnit, getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, getWidth, getWidthUnit, setHeight, setHeight, setHeightFull, setMaxHeight, setMaxHeight, setMaxWidth, setMaxWidth, setMinHeight, setMinHeight, setMinWidth, setMinWidth, setSizeFull, setSizeUndefined, setWidth, setWidth, setWidthFull

    Methods inherited from interface com.vaadin.flow.component.HasStyle

    addClassName, addClassNames, getClassName, getClassNames, getStyle, hasClassName, removeClassName, removeClassNames, setClassName, setClassName

    Methods inherited from interface com.vaadin.flow.component.HasTheme

    addThemeName, addThemeNames, getThemeName, getThemeNames, hasThemeName, removeThemeName, removeThemeNames, setThemeName, setThemeName

    Methods inherited from interface com.vaadin.flow.component.shared.HasThemeVariant

    addThemeVariants, removeThemeVariants
  • Constructor Details

    • MenuBar

      public MenuBar()
      Creates an empty menu bar component.

      Use addItem(String) to add content to the menu bar.

  • Method Details

    • addItem

      public MenuItem addItem(String text)
      Creates a new MenuItem component with the provided text content and adds it to the root level of this menu bar.

      The added MenuItem component is placed inside a button in the menu bar. If this button overflows the menu bar horizontally, the MenuItem is moved out of the button, into a context menu openable via an overflow button at the end of the button row.

      To add content to the sub menu opened by clicking the root level item, use MenuItemBase.getSubMenu().

      Parameters:
      text - the text content for the new item
      Returns:
      the added MenuItem component
    • addItem

      public MenuItem addItem(com.vaadin.flow.component.Component component)
      Creates a new MenuItem component and adds it to the root level of this menu bar. The provided component is added into the created MenuItem.

      The added MenuItem component is placed inside a button in the menu bar. If this button overflows the menu bar horizontally, the MenuItem is moved out of the button, into a context menu openable via an overflow button at the end of the button row.

      To add content to the sub menu opened by clicking the root level item, use MenuItemBase.getSubMenu().

      Parameters:
      component - the component to add inside new item
      Returns:
      the added MenuItem component
    • addItem

      public MenuItem addItem(String text, com.vaadin.flow.component.ComponentEventListener<com.vaadin.flow.component.ClickEvent<MenuItem>> clickListener)
      Creates a new MenuItem component with the provided text content and click listener and adds it to the root level of this menu bar.

      The added MenuItem component is placed inside a button in the menu bar. If this button overflows the menu bar horizontally, the MenuItem is moved out of the button, into a context menu openable via an overflow button at the end of the button row.

      To add content to the sub menu opened by clicking the root level item, use MenuItemBase.getSubMenu().

      Specified by:
      addItem in interface HasMenuItems
      Parameters:
      text - the text content for the new item
      clickListener - the handler for clicking the new item, can be null to not add listener
      Returns:
      the added MenuItem component
    • addItem

      public MenuItem addItem(com.vaadin.flow.component.Component component, com.vaadin.flow.component.ComponentEventListener<com.vaadin.flow.component.ClickEvent<MenuItem>> clickListener)
      Creates a new MenuItem component with the provided click listener and adds it to the root level of this menu bar. The provided component is added into the created MenuItem.

      The added MenuItem component is placed inside a button in the menu bar. If this button overflows the menu bar horizontally, the MenuItem is moved out of the button, into a context menu openable via an overflow button at the end of the button row.

      To add content to the sub menu opened by clicking the root level item, use MenuItemBase.getSubMenu().

      Specified by:
      addItem in interface HasMenuItems
      Parameters:
      component - the component to add inside the added menu item
      clickListener - the handler for clicking the new item, can be null to not add listener
      Returns:
      the added MenuItem component
    • addItem

      public MenuItem addItem(String text, String tooltipText)
      Creates a new MenuItem component with the provided text content and the tooltip text and adds it to the root level of this menu bar.

      The added MenuItem component is placed inside a button in the menu bar. If this button overflows the menu bar horizontally, the MenuItem is moved out of the button, into a context menu openable via an overflow button at the end of the button row.

      To add content to the sub menu opened by clicking the root level item, use MenuItemBase.getSubMenu().

      Parameters:
      text - the text content for the new item
      tooltipText - the tooltip text for the new item
      Returns:
      the added MenuItem component
    • addItem

      public MenuItem addItem(com.vaadin.flow.component.Component component, String tooltipText)
      Creates a new MenuItem component with the provided tooltip text and adds it to the root level of this menu bar. The provided component is added into the created MenuItem.

      The added MenuItem component is placed inside a button in the menu bar. If this button overflows the menu bar horizontally, the MenuItem is moved out of the button, into a context menu openable via an overflow button at the end of the button row.

      To add content to the sub menu opened by clicking the root level item, use MenuItemBase.getSubMenu().

      Parameters:
      component - the component to add inside new item
      tooltipText - the tooltip text for the new item
      Returns:
      the added MenuItem component
    • addItem

      public MenuItem addItem(String text, String tooltipText, com.vaadin.flow.component.ComponentEventListener<com.vaadin.flow.component.ClickEvent<MenuItem>> clickListener)
      Creates a new MenuItem component with the provided text content and the tooltip text and click listener and adds it to the root level of this menu bar.

      The added MenuItem component is placed inside a button in the menu bar. If this button overflows the menu bar horizontally, the MenuItem is moved out of the button, into a context menu openable via an overflow button at the end of the button row.

      To add content to the sub menu opened by clicking the root level item, use MenuItemBase.getSubMenu().

      Parameters:
      text - the text content for the new item
      tooltipText - the tooltip text for the new item
      clickListener - the handler for clicking the new item, can be null to not add listener
      Returns:
      the added MenuItem component
    • addItem

      public MenuItem addItem(com.vaadin.flow.component.Component component, String tooltipText, com.vaadin.flow.component.ComponentEventListener<com.vaadin.flow.component.ClickEvent<MenuItem>> clickListener)
      Creates a new MenuItem component with the provided click listener and the tooltip text and adds it to the root level of this menu bar. The provided component is added into the created MenuItem.

      The added MenuItem component is placed inside a button in the menu bar. If this button overflows the menu bar horizontally, the MenuItem is moved out of the button, into a context menu openable via an overflow button at the end of the button row.

      To add content to the sub menu opened by clicking the root level item, use MenuItemBase.getSubMenu().

      Parameters:
      component - the component to add inside the added menu item
      tooltipText - the tooltip text for the new item
      clickListener - the handler for clicking the new item, can be null to not add listener
      Returns:
      the added MenuItem component
    • getItems

      public List<MenuItem> getItems()
      Gets the MenuItem components added to the root level of the menu bar.

      To manage the contents inside the sub menus, use the MenuItemBase.getSubMenu().

      Returns:
      the root level MenuItem components added to this menu bar
    • remove

      public void remove(MenuItem... items)
      Removes the given item components from this menu bar.
      Parameters:
      items - the item components to remove, not null
      Throws:
      IllegalArgumentException - if any of the item components to remove is not a child of this menu bar
    • removeAll

      public void removeAll()
      Removes all item components from this menu bar.
    • getChildren

      public Stream<com.vaadin.flow.component.Component> getChildren()
      Gets the child components of this menu bar.

      The returned components are the same as the ones returned by getItems().

      Overrides:
      getChildren in class com.vaadin.flow.component.Component
      Returns:
      the child components of this menu bar
    • setOpenOnHover

      public void setOpenOnHover(boolean openOnHover)
      Sets the event which opens the sub menus of the root level buttons.
      Parameters:
      openOnHover - true to make the sub menus open on hover (mouseover), false to make them openable by clicking
    • isOpenOnHover

      public boolean isOpenOnHover()
      Gets whether the sub menus open by clicking or hovering on the root level buttons.
      Returns:
      true if the sub menus open by hovering on the root level buttons, false if they open by clicking
    • setReverseCollapseOrder

      public void setReverseCollapseOrder(boolean reverseCollapseOrder)
      Sets reverse collapse order for the menu bar.
      Parameters:
      reverseCollapseOrder - If true, the buttons will be collapsed into the overflow menu starting from the "start" end of the bar instead of the "end".
    • isReverseCollapseOrder

      public boolean isReverseCollapseOrder()
      Gets whether the menu bar uses reverse collapse order.
      Returns:
      true if the buttons will be collapsed into the overflow menu starting from the "start" end of the bar instead of the "end".
    • setTabNavigation

      public void setTabNavigation(boolean tabNavigation)
      Sets tab navigation for the menu bar.
      Parameters:
      tabNavigation - If true, the top-level menu items is traversable by tab instead of arrow keys (i.e. disabling roving tabindex)
    • isTabNavigation

      public boolean isTabNavigation()
      Gets whether the menu bar uses tab navigation.
      Returns:
      true if the top-level menu items is traversable by tab instead of arrow keys (i.e. disabling roving tabindex)
    • getI18n

      public MenuBar.MenuBarI18n getI18n()
      Gets the internationalization object previously set for this component.

      NOTE: Updating the instance that is returned from this method will not update the component if not set again using setI18n(MenuBarI18n)

      Returns:
      the i18n object or null if no i18n object has been set
    • setI18n

      public void setI18n(MenuBar.MenuBarI18n i18n)
      Sets the internationalization object for this component.
      Parameters:
      i18n - the i18n object, not null
    • onAttach

      protected void onAttach(com.vaadin.flow.component.AttachEvent attachEvent)
      Overrides:
      onAttach in class com.vaadin.flow.component.Component
    • setTooltipText

      public void setTooltipText(MenuItem item, String tooltipText)
      Sets the tooltip text for the given MenuItem.
      Parameters:
      item - the menu item to set the tooltip for
      tooltipText - the tooltip text to set for the item
    • close

      public void close()
      Closes the current submenu.