Class SideNavRailItem

java.lang.Object
com.vaadin.flow.component.Component
com.vaadin.flow.component.sidenav.SideNavItem
org.vaadin.addons.componentfactory.sidenavrail.SideNavRailItem
All Implemented Interfaces:
com.vaadin.flow.component.AttachNotifier, com.vaadin.flow.component.DetachNotifier, com.vaadin.flow.component.HasElement, com.vaadin.flow.component.HasEnabled, com.vaadin.flow.component.HasStyle, com.vaadin.flow.component.shared.HasPrefix, com.vaadin.flow.component.shared.HasSuffix, com.vaadin.flow.component.shared.HasTooltip, com.vaadin.flow.component.sidenav.HasSideNavItems, Serializable

public class SideNavRailItem extends com.vaadin.flow.component.sidenav.SideNavItem
SideNavItem variant that integrates with SideNavRail's rail mode and hover popover. API-compatible with SideNavItem — drop in anywhere you would use SideNavItem under a SideNavRail.

Two things happen beyond the standard item:

  • The string label is wrapped in a <span class="label"> so rail-mode CSS (which selects vaadin-side-nav[theme~="rail"] vaadin-side-nav-item .label) can hide it. A bare text node cannot be targeted by CSS.
  • Items that have children lazily attach a Popover on first attach. The popover's hover-trigger eligibility is gated by the owning SideNavRail's PopoverOn and rail state — see SideNavRail.setPopoverOn(PopoverOn) for the full behaviour matrix.

Typical usage:


 SideNavRail rail = new SideNavRail();
 SideNavRailItem code = new SideNavRailItem("Code", "/code", VaadinIcon.CODE.create());
 code.addItem(new SideNavRailItem("Branches", "/code/branches"));
 rail.addItem(code);
 
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    Non-navigating container item.
    SideNavRailItem(String label, Class<? extends com.vaadin.flow.component.Component> view)
    Item navigating to the given Flow route class.
    SideNavRailItem(String label, Class<? extends com.vaadin.flow.component.Component> view, com.vaadin.flow.component.Component prefixComponent)
    Item navigating to a Flow route class, with a prefix component on the left.
    Item navigating to the given path (server- or client-side route).
    SideNavRailItem(String label, String path, com.vaadin.flow.component.Component prefixComponent)
    Item navigating to a path, with a prefix component rendered on the left (typically an icon).
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addItem(com.vaadin.flow.component.sidenav.SideNavItem... items)
    void
    addItemAsFirst(com.vaadin.flow.component.sidenav.SideNavItem item)
    void
    addItemAtIndex(int index, com.vaadin.flow.component.sidenav.SideNavItem item)
    Optional<com.vaadin.flow.component.popover.Popover>
    Returns the popover of this item, if one has been created.
    protected void
    onAttach(com.vaadin.flow.component.AttachEvent event)
     
    protected void
    onDetach(com.vaadin.flow.component.DetachEvent event)
     
    void
    remove(com.vaadin.flow.component.sidenav.SideNavItem... items)
    void
    void
    void
    setPrefixComponent(com.vaadin.flow.component.Component prefix)

    Methods inherited from class com.vaadin.flow.component.sidenav.SideNavItem

    getLabel, getPath, getPathAliases, getTarget, isExpanded, isMatchNested, isOpenInNewBrowserTab, isRouterIgnore, setExpanded, setMatchNested, setOpenInNewBrowserTab, setPath, setPath, setPath, setPath, setPathAliases, setQueryParameters, setRouterIgnore, setTarget

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

    addListener, findAncestor, fireEvent, from, get, getChildren, getElement, getEventBus, getId, getListeners, getLocale, getParent, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getUI, hasListener, isAttached, isTemplateMapped, isVisible, 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.shared.HasPrefix

    getPrefixComponent

    Methods inherited from interface com.vaadin.flow.component.sidenav.HasSideNavItems

    getItems

    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.shared.HasSuffix

    getSuffixComponent, setSuffixComponent

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

    getTooltip, setTooltipText
  • Constructor Details

    • SideNavRailItem

      public SideNavRailItem(String label)
      Non-navigating container item. Click does nothing; useful as a parent for children.
      Parameters:
      label - the visible label of the item; may be null for an unlabelled item, in which case the rail-mode letter-avatar fallback is suppressed
    • SideNavRailItem

      public SideNavRailItem(String label, String path)
      Item navigating to the given path (server- or client-side route).
      Parameters:
      label - the visible label of the item; may be null
      path - the route path the item navigates to on click; may be null for a non-navigating item
    • SideNavRailItem

      public SideNavRailItem(String label, Class<? extends com.vaadin.flow.component.Component> view)
      Item navigating to the given Flow route class.
      Parameters:
      label - the visible label of the item; may be null
      view - the Flow view class the item navigates to on click; must not be null
    • SideNavRailItem

      public SideNavRailItem(String label, String path, com.vaadin.flow.component.Component prefixComponent)
      Item navigating to a path, with a prefix component rendered on the left (typically an icon).
      Parameters:
      label - the visible label of the item; may be null
      path - the route path the item navigates to on click; may be null for a non-navigating item
      prefixComponent - the component rendered to the left of the label (typically a VaadinIcon or an Avatar); may be null, in which case the rail-mode letter-avatar fallback kicks in
    • SideNavRailItem

      public SideNavRailItem(String label, Class<? extends com.vaadin.flow.component.Component> view, com.vaadin.flow.component.Component prefixComponent)
      Item navigating to a Flow route class, with a prefix component on the left.
      Parameters:
      label - the visible label of the item; may be null
      view - the Flow view class the item navigates to on click; must not be null
      prefixComponent - the component rendered to the left of the label (typically a VaadinIcon or an Avatar); may be null, in which case the rail-mode letter-avatar fallback kicks in
  • Method Details

    • setLabel

      public void setLabel(String label)

      Overridden to re-wrap the label in <span class="label"> so CSS can hide it in rail mode, and to refresh the auto-generated letter-avatar fallback (see ensureLetterAvatar()) so it matches the new label's first letter. Idempotent across repeated calls.

      Overrides:
      setLabel in class com.vaadin.flow.component.sidenav.SideNavItem
      Parameters:
      label - the new label text; may be null
    • setPrefixComponent

      public void setPrefixComponent(com.vaadin.flow.component.Component prefix)

      Overridden so that setting the prefix back to null re-generates the letter-avatar fallback (otherwise a user-removed icon would leave the item unmarked in rail mode). Passing a real component (icon, image, …) replaces the avatar as usual — the override is a no-op in that case.

      Parameters:
      prefix - the new prefix component (typically a VaadinIcon or an Avatar); pass null to fall back to the auto-generated letter avatar
    • addItem

      public void addItem(com.vaadin.flow.component.sidenav.SideNavItem... items)

      Only accepts SideNavRailItem children. Passing a plain SideNavItem throws IllegalArgumentException — nested items need the same label-wrap + popover-gating wiring the parent has.

      Parameters:
      items - the SideNavRailItem children to append below this item
      Throws:
      IllegalArgumentException - if any item is not a SideNavRailItem
    • addItemAsFirst

      public void addItemAsFirst(com.vaadin.flow.component.sidenav.SideNavItem item)
      Parameters:
      item - the SideNavRailItem to prepend below this item
      Throws:
      IllegalArgumentException - if the item is not a SideNavRailItem; see addItem(SideNavItem...)
    • addItemAtIndex

      public void addItemAtIndex(int index, com.vaadin.flow.component.sidenav.SideNavItem item)
      Parameters:
      index - where to insert the item
      item - the SideNavRailItem to insert
      Throws:
      IllegalArgumentException - if the item is not a SideNavRailItem; see addItem(SideNavItem...)
    • remove

      public void remove(com.vaadin.flow.component.sidenav.SideNavItem... items)

      Removed children are also reflected in the popover (if any).

    • removeAll

      public void removeAll()

      The popover (if any) is rebuilt with no children.

    • onAttach

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

      protected void onDetach(com.vaadin.flow.component.DetachEvent event)
      Overrides:
      onDetach in class com.vaadin.flow.component.Component
    • getPopover

      public Optional<com.vaadin.flow.component.popover.Popover> getPopover()
      Returns the popover of this item, if one has been created. The popover is lazily attached on first attach: items with children always get one, while leaf items get one only when the owning rail's RailTooltipMode is POPOVER_HEADER and rail-mode is active (see SideNavRail.isLeafPopoverActive()). Items that have not been attached yet, or that are not part of a rail, return Optional.empty().
      Returns:
      an Optional containing the underlying Popover, or Optional.empty() if none has been created