Class SideNav

java.lang.Object
com.vaadin.flow.component.Component
com.vaadin.flow.component.sidenav.SideNav
All Implemented Interfaces:
AttachNotifier, DetachNotifier, HasElement, HasSize, HasStyle, Serializable

@Tag("vaadin-side-nav") @NpmPackage(value="@vaadin/side-nav", version="24.3.11") @JsModule("@vaadin/side-nav/src/vaadin-side-nav.js") public class SideNav extends Component implements HasSize, HasStyle
A side navigation menu with support for hierarchical and flat menus.

Items can be added using addItem(SideNavItem...) and hierarchy can be created by adding SideNavItem instances to other SideNavItem instances.

Author:
Vaadin Ltd
See Also:
  • Constructor Details

    • SideNav

      public SideNav()
      Creates a new menu without any label.
    • SideNav

      public SideNav(String label)
      Creates a new menu with the given label.
      Parameters:
      label - the label to use
  • Method Details

    • getLabel

      public String getLabel()
      Gets the label of this side navigation menu.
      Returns:
      the label or null if no label has been set
    • setLabel

      public void setLabel(String label)
      Set a textual label for this side navigation menu.

      This label can help the end user to distinguish groups of navigation items. The label is also available for screen reader users.

      Parameters:
      label - the label text to set; or null to remove the label
    • isCollapsible

      public boolean isCollapsible()
      Check if the end user is allowed to collapse/hide and expand/show the navigation items.

      NOTE: The navigation has to have a label for it to be collapsible.

      Returns:
      true if the menu is collapsible, false otherwise
    • setCollapsible

      public void setCollapsible(boolean collapsible)
      Allow the end user to collapse/hide and expand/show the navigation items.

      NOTE: The navigation has to have a label for it to be collapsible.

      Parameters:
      collapsible - true to make the whole navigation component collapsible, false otherwise
    • isExpanded

      @Synchronize(property="collapsed", value="collapsed-changed") public boolean isExpanded()
      Returns whether the side navigation menu is expanded or collapsed.
      Returns:
      true if the side navigation menu is expanded, false if collapsed
    • setExpanded

      public void setExpanded(boolean expanded)
      Expands the side navigation menu.

      If the side navigation menu does not have a label, does nothing.

    • getI18n

      public SideNav.SideNavI18n getI18n()
      Gets the internationalization object previously set for this component.

      Note: updating the object content that is gotten from this method will not update the lang on the component if not set back using setI18n(SideNavI18n)

      Returns:
      the i18n object. It will be null, If the i18n properties weren't set.
    • setI18n

      public void setI18n(SideNav.SideNavI18n i18n)
      Updates the i18n settings in the web component. Merges the SideNav.SideNavI18n settings with the current / default settings of the web component.
      Parameters:
      i18n - the internationalized properties, not null
    • setupSideNavItem

      protected void setupSideNavItem(SideNavItem item)
      Implement this method to set up/modify the SideNavItem right before it's added to the list of the navigation items.
      Parameters:
      item - Item to be set up
    • addItem

      public void addItem(SideNavItem... items)
      Adds navigation menu item(s) to the menu.
      Parameters:
      items - the navigation menu item(s) to add
    • addItemAsFirst

      public void addItemAsFirst(SideNavItem item)
      Adds the given navigation item as the first child of this navigation item.
      Parameters:
      item - the item to add, value must not be null
    • addItemAtIndex

      public void addItemAtIndex(int index, SideNavItem item)
      Adds the given item as child of this navigation item at the specific index.
      Parameters:
      index - the index, where the item will be added. The index must be non-negative and may not exceed the children count
      item - the item to add, value must not be null
    • getItems

      public List<SideNavItem> getItems()
      Gets the items added to this navigation item (the children of this component that are instances of SideNavItem). This doesn't include the items added to the children of this navigation item.
      Returns:
      the child SideNavItem instances in this navigation menu
      See Also:
    • remove

      public void remove(SideNavItem... items)
      Removes the menu item(s) from the menu.

      If the given menu item is not a child of this menu, does nothing.

      Parameters:
      items - the menu item(s) to remove
    • removeAll

      public void removeAll()
      Removes all navigation menu items from this item.