Class Menu

All Implemented Interfaces:
Attachable, ElementAttributeMethods<HTMLDivElement, Menu>, ElementClassListMethods<HTMLDivElement, Menu>, ElementConsumerMethods<HTMLDivElement, Menu>, ElementContainerMethods<HTMLDivElement, Menu>, ElementEventMethods<HTMLDivElement, Menu>, ElementIdMethods<HTMLDivElement, Menu>, ElementQueryMethods<HTMLDivElement>, HTMLElementAttributeMethods<HTMLDivElement, Menu>, HTMLElementDataMethods<HTMLDivElement, Menu>, HTMLElementStyleMethods<HTMLDivElement, Menu>, HTMLElementVisibilityMethods<HTMLDivElement, Menu>, IsElement<HTMLDivElement>, TypedBuilder<HTMLDivElement, Menu>, Component, OuiaSupport<HTMLDivElement, Menu>, Modifiers.Plain<HTMLDivElement, Menu>
Direct Known Subclasses:
DropdownMenu, MultiSelectMenu, SingleSelectMenu

A menu is a list of options or actions that users can choose from. It can be used in a variety of contexts whenever the user needs to choose between multiple values, options, or actions. A menu is most often paired with a MenuToggle as its trigger, but can also be used inline or can be attached to other interactable elements to toggle it open and close.

Menu menu = menu(MenuType.menu, click)
        .scrollable()
        .height("200px")
        .addHeader("Header")
        .addContent(menuContent()
                .addList(menuList()
                        .addItem(MenuItem.menuItem("1", "Item 1"))
                        .addItem(MenuItem.menuItem("2", "Item 2"))
                        .addDivider()
                        .addItem(MenuItem.linkMenuItem("3", "Item 3", "#third"))))
        .addFooter(menuFooter()
                .add(button("Footer")));
See Also:
  • Method Details

    • attach

      public void attach(MutationRecord mutationRecord)
      Specified by:
      attach in interface Attachable
    • detach

      public void detach(MutationRecord mutationRecord)
      Specified by:
      detach in interface Attachable
    • addHeader

      public Menu addHeader(String text)
      Shortcut for addHeader(menuHeader(text))
    • addHeader

      public Menu addHeader(MenuHeader header)
    • addContent

      public Menu addContent(MenuContent content)
    • add

      public Menu add(MenuContent content)
    • addFooter

      public Menu addFooter(String text)
      Shortcut for addFooter(menuFooter(text))
    • addFooter

      public Menu addFooter(MenuFooter footer)
    • addSearch

      public Menu addSearch(MenuSearch search)
    • addDivider

      public Menu addDivider()
    • favorites

      public Menu favorites()
    • flyout

      public Menu flyout()
    • height

      public Menu height(String height)
      Sets the --pf-v5-c-menu__content--MaxHeight variable to the specified value
    • error

      public Menu error(Supplier<MenuItem> error)
      Sets the error indicator supplier for all menu lists. Pass null to disable the indicator.
    • loading

      public Menu loading(Supplier<MenuItem> loading)
      Sets the loading indicator supplier for all menu lists. Pass null to disable the indicator.
    • noItems

      public Menu noItems(Supplier<MenuItem> noItems)
      Sets the "no items" indicator supplier for all menu lists. Pass null to disable the indicator. When disabled, the menu will simply remain empty (and typically collapse) when async items return an empty result.
    • scrollable

      public Menu scrollable()
    • that

      public Menu that()
      Specified by:
      that in interface TypedBuilder<HTMLDivElement, Menu>
    • onAction

      public Menu onAction(MenuActionHandler actionHandler)
    • onSingleSelect

      public Menu onSingleSelect(SelectHandler<MenuItem> selectHandler)
    • onMultiSelect

      public Menu onMultiSelect(MultiSelectHandler<Menu,MenuItem> selectHandler)
    • allowTabFirstItem

      public void allowTabFirstItem()
      Sets the `tabIndex` property of the first focusable item within a menu to `0`, allowing it to be reachable via the Tab key. Focusable items are identified as non-disabled `
    • cursorNavigation

      Handles arrow up/down events when focus is outside the menu (e.g., in a MenuToggle search input or a BaseSearchInputGroup text field). Moves focus to the first (ArrowDown) or last (ArrowUp) navigable menu item.

      This method is the entry point into menu keyboard navigation. Once focus has moved inside the menu, handleArrows(KeyboardEvent, HTMLElement, JsArray) takes over and cycles through items relative to the current position.

      Parameters:
      event - the keyboard event triggered when an arrow key is pressed
    • findItem

      public MenuItem findItem(String identifier)
    • hasAsyncItems

      public boolean hasAsyncItems()
      Checks if the menu contains any asynchronous items that are currently in a pending status. This method inspects the menu lists to determine if any status is pending.
      Returns:
      true if any MenuList has a status of pending, otherwise false.
    • items

      public List<MenuItem> items()
    • load

      public Promise<Void> load()
    • refresh

      public Promise<Void> refresh()
    • reset

      public void reset()
    • select

      public void select(String identifier)
    • select

      public void select(String identifier, boolean selected)
    • select

      public void select(String identifier, boolean selected, boolean fireEvent)
    • select

      public void select(MenuItem item)
    • select

      public void select(MenuItem item, boolean selected)
    • select

      public void select(MenuItem item, boolean selected, boolean fireEvent)
    • selectedItems

      public List<MenuItem> selectedItems()
    • search

      public List<MenuItem> search(SearchFilter searchFilter, NoResults noResults, String value)
      Filters the menu items based on the given search value. Each menu item is tested against the search filter; items that don't match are hidden using the filtered modifier CSS class. If no items match and a noResults handler is provided, a "no results" item is added to the menu list. If the menu contains asynchronous (pending) items, the search is skipped and an empty list is returned.
      Parameters:
      searchFilter - the filter used to determine whether a menu item matches the search value
      noResults - the handler that creates a "no results" menu item when no items match; can be null to skip showing a no-results indicator
      value - the search text to filter menu items against
      Returns:
      the list of visible (matching) items after filtering, or an empty list if the search was skipped because the menu contains pending asynchronous items
    • clearSearch

      public void clearSearch()
      Clears the current search filtering state within the menu.

      This method performs the following actions: - Removes the "no results" item from the parent container, if it exists. - Iterates through all menu items and removes the `filtered` CSS modifier class, ensuring that all items are visible again. - Resets keyboard navigation accessibility by enabling the first focusable item to have a `tabIndex` of `0`.