Class SideNavRail
- All Implemented Interfaces:
com.vaadin.flow.component.AttachNotifier,com.vaadin.flow.component.DetachNotifier,com.vaadin.flow.component.HasElement,com.vaadin.flow.component.HasSize,com.vaadin.flow.component.HasStyle,com.vaadin.flow.component.sidenav.HasSideNavItems,Serializable
SideNav that can be switched into a compact icon-only rail mode and shows a
hover popover for items with children. The item tree must be built from SideNavRailItems;
addItem(SideNavItem...) rejects a plain SideNavItem with an IllegalArgumentException, because
only SideNavRailItem carries the CSS label-wrap and popover-gating wiring.
The component toggles between two visual states:
- Normal mode — behaves like a standard
SideNav. - Rail mode — the
theme="rail"attribute is set on the root element and bundled CSS collapses the nav to a narrow icon-only column. Inline expansion state is preserved (just visually suppressed) and restored when switching back.
Typical usage inside a layout:
SideNavRail rail = new SideNavRail();
rail.addItem(new SideNavRailItem("Dashboard", DashboardView.class, VaadinIcon.DASHBOARD.create()));
// ...
Button toggle = new Button("Rail", e -> rail.setRailMode(!rail.isRailMode()));
The component does not ship with a toggle button — applications integrate one where it fits their layout. This is intentional: auto-collapse, persistent state, and responsive breakpoint handling are the application's concern.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class com.vaadin.flow.component.sidenav.SideNav
com.vaadin.flow.component.sidenav.SideNav.SideNavI18n -
Constructor Summary
ConstructorsConstructorDescriptionCreates an unlabelled rail.SideNavRail(String label) Creates a rail with a header label. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddItem(com.vaadin.flow.component.sidenav.SideNavItem... items) voidaddItemAsFirst(com.vaadin.flow.component.sidenav.SideNavItem item) voidaddItemAtIndex(int index, com.vaadin.flow.component.sidenav.SideNavItem item) com.vaadin.flow.shared.RegistrationaddRailModeChangedListener(com.vaadin.flow.component.ComponentEventListener<RailModeChangedEvent> listener) Registers a listener forRailModeChangedEvent.The first match fromgetActiveViewItems(), or empty if no item matches.Returns all rail items whose own path (or any of their path aliases) equals the current view's location.The current header mode for popovers.intThe hide delay (ms) after the pointer leaves the target before the popover closes.intThe hover delay (ms) before the popover opens.The current popover mode.com.vaadin.flow.component.popover.PopoverPositionThe position the popover opens at relative to its item.The current rail-tooltip mode.The currentRootMatchNestedmode.booleanWhether nested items are rendered only inside the hover popover, never inline below their parent.booleanWhether the rail currently asksSideNavRailItemto create a popover for a leaf (childless) root item, so the popover can act as a Vaadin-themed tooltip.booleanWhether each popover renders the small Lumo arrow pointing back at its target item.booleanWhether the popover header is rendered only while the rail is in rail mode.booleanWhether the rail is currently in icon-only mode.protected voidonAttach(com.vaadin.flow.component.AttachEvent attachEvent) protected voidonDetach(com.vaadin.flow.component.DetachEvent detachEvent) voidsetChildrenOnlyInPopover(boolean enabled) Switches between the standard inline-and-popover layout for nested items (false, default) and a popover-only layout (true).voidsetPopoverArrowVisible(boolean visible) Sets whether each popover renders the small Lumo arrow pointing back at its target item.voidSets whether (and how) each popover renders a header identifying the owning item.voidsetPopoverHeaderOnlyInRailMode(boolean onlyInRailMode) Restricts the popover header to rail mode, or allows it in both modes.voidsetPopoverHideDelay(int hideDelayMs) Sets the hide delay (ms) after the pointer leaves the target before the popover closes.voidsetPopoverHoverDelay(int hoverDelayMs) Sets the hover delay (ms) before the popover opens.voidsetPopoverOn(PopoverOn mode) Sets the popover mode.voidsetPopoverPosition(com.vaadin.flow.component.popover.PopoverPosition position) Sets the popover position.voidsetRailMode(boolean railMode) Switches the rail between normal mode and icon-only rail mode.voidControls how root items surface their label while the rail is in rail mode.voidSets theRootMatchNestedmode.voidSwitches the rail between normal mode and icon-only rail mode.Methods inherited from class com.vaadin.flow.component.sidenav.SideNav
getI18n, getLabel, isCollapsible, isExpanded, setCollapsible, setExpanded, setI18n, setLabelMethods 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, setVisibleMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.vaadin.flow.component.AttachNotifier
addAttachListenerMethods inherited from interface com.vaadin.flow.component.DetachNotifier
addDetachListenerMethods inherited from interface com.vaadin.flow.component.HasElement
getElementMethods inherited from interface com.vaadin.flow.component.sidenav.HasSideNavItems
getItems, remove, removeAllMethods 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, setWidthFullMethods inherited from interface com.vaadin.flow.component.HasStyle
addClassName, addClassNames, getClassName, getClassNames, getStyle, hasClassName, removeClassName, removeClassNames, setClassName, setClassName
-
Constructor Details
-
SideNavRail
public SideNavRail()Creates an unlabelled rail. -
SideNavRail
Creates a rail with a header label. SeeSideNav.setLabel(String)for the semantics — the label renders above the item list and can be used to group multipleSideNavinstances visually.- Parameters:
label- the header label rendered above the item list; may benullfor an unlabelled rail
-
-
Method Details
-
onAttach
protected void onAttach(com.vaadin.flow.component.AttachEvent attachEvent) - Overrides:
onAttachin classcom.vaadin.flow.component.Component
-
onDetach
protected void onDetach(com.vaadin.flow.component.DetachEvent detachEvent) - Overrides:
onDetachin classcom.vaadin.flow.component.Component
-
toggleRailMode
public void toggleRailMode()Switches the rail between normal mode and icon-only rail mode. Fires aRailModeChangedEvent. -
setRailMode
public void setRailMode(boolean railMode) Switches the rail between normal mode and icon-only rail mode. No-op if the state is unchanged; otherwise fires aRailModeChangedEvent.- Parameters:
railMode-trueto enter rail mode (icon-only),falseto return to normal mode (full-width with labels)
-
isRailMode
public boolean isRailMode()Whether the rail is currently in icon-only mode.- Returns:
trueif the rail is in rail mode,falsein normal mode
-
getPopoverOn
The current popover mode. Default:PopoverOn.ALL_COLLAPSED_ITEMS. SeePopoverOnfor the full behaviour matrix.- Returns:
- the active
PopoverOn; nevernull
-
getPopoverHeaderMode
The current header mode for popovers. Default:PopoverHeaderMode.LABEL_ONLY. SeePopoverHeaderModefor the rendering rules per value.- Returns:
- the active
PopoverHeaderMode; nevernull
-
isPopoverHeaderOnlyInRailMode
public boolean isPopoverHeaderOnlyInRailMode()Whether the popover header is rendered only while the rail is in rail mode. Default:true(header is hidden in normal mode, where the item's label is already visible inline). Has no effect while theheader modeisPopoverHeaderMode.NONE.- Returns:
trueif the header is restricted to rail mode,falseif it is rendered in both modes
-
setPopoverHeaderOnlyInRailMode
public void setPopoverHeaderOnlyInRailMode(boolean onlyInRailMode) Restricts the popover header to rail mode, or allows it in both modes. Default:true. Useful in combination withsetChildrenOnlyInPopover(boolean), where the popover is the only place children appear even in normal mode and an item-identifying header may still be desired.Has no visible effect while
getPopoverHeaderMode()isPopoverHeaderMode.NONE. Rebuilds the content of all existing popovers so the change is visible immediately.- Parameters:
onlyInRailMode-trueto render the header only in rail mode,falseto render it in both modes
-
getRailTooltipMode
The current rail-tooltip mode. Default:RailTooltipMode.POPOVER_HEADER. Tooltips are only shown while the rail is in rail mode; seeRailTooltipModefor the per-value semantics.- Returns:
- the active
RailTooltipMode; nevernull
-
isLeafPopoverActive
public boolean isLeafPopoverActive()Whether the rail currently asksSideNavRailItemto create a popover for a leaf (childless) root item, so the popover can act as a Vaadin-themed tooltip. True iff rail mode is active andRailTooltipMode.POPOVER_HEADERis selected.- Returns:
trueif leaf items should have a popover,falseotherwise
-
getPopoverHoverDelay
public int getPopoverHoverDelay()The hover delay (ms) before the popover opens. Default: 200 ms (Lumo-typical).- Returns:
- the hover delay in milliseconds
-
setPopoverHoverDelay
public void setPopoverHoverDelay(int hoverDelayMs) Sets the hover delay (ms) before the popover opens. Applied to every existing popover immediately. Negative values behave as Vaadin'sPopoverdefines them — the addon does not validate.- Parameters:
hoverDelayMs- the new hover delay in milliseconds
-
getPopoverHideDelay
public int getPopoverHideDelay()The hide delay (ms) after the pointer leaves the target before the popover closes. Default: 300 ms (Lumo-typical).- Returns:
- the hide delay in milliseconds
-
setPopoverHideDelay
public void setPopoverHideDelay(int hideDelayMs) Sets the hide delay (ms) after the pointer leaves the target before the popover closes. Applied to every existing popover immediately.- Parameters:
hideDelayMs- the new hide delay in milliseconds
-
getPopoverPosition
public com.vaadin.flow.component.popover.PopoverPosition getPopoverPosition()The position the popover opens at relative to its item. Default:PopoverPosition.END_TOP— top-aligned, to the inline-end of the item (right in an LTR layout). Suitable for a rail pinned to the inline-start edge.- Returns:
- the active
PopoverPosition; nevernull
-
setPopoverPosition
public void setPopoverPosition(com.vaadin.flow.component.popover.PopoverPosition position) Sets the popover position. Applied to every existing popover immediately.- Parameters:
position- the newPopoverPosition; must not benull- Throws:
NullPointerException- ifpositionisnull
-
isPopoverArrowVisible
public boolean isPopoverArrowVisible()Whether each popover renders the small Lumo arrow pointing back at its target item. Default:true(arrow visible — applies thearrowtheme variant of<vaadin-popover>).- Returns:
trueif the arrow is shown,falseif hidden
-
setPopoverArrowVisible
public void setPopoverArrowVisible(boolean visible) Sets whether each popover renders the small Lumo arrow pointing back at its target item. Applied to every existing popover immediately.- Parameters:
visible-trueto show the arrow (default),falseto hide it (cleaner look when popovers are tightly packed against the rail)
-
isChildrenOnlyInPopover
public boolean isChildrenOnlyInPopover()Whether nested items are rendered only inside the hover popover, never inline below their parent. Default:false(children are visible inline and mirrored into the popover — Vaadin's standard behaviour).- Returns:
trueif inline children are suppressed
-
setChildrenOnlyInPopover
public void setChildrenOnlyInPopover(boolean enabled) Switches between the standard inline-and-popover layout for nested items (false, default) and a popover-only layout (true). When enabled, nested<vaadin-side-nav-item>s are CSS-hidden and the chevron toggle is suppressed, so the only path to a parent's children is the hover popover. Useful for navigation designs that want a flat, non-tree appearance in the rail itself.While enabled, this overrides
setPopoverOn(PopoverOn): the hover popover is always shown on root items with children (in both rail and normal mode), since it is the only path to their children.Vaadin's auto-expand-on-route-match still fires server-side, but has no visual effect while this is on; switching the flag back to
falserestores the default tree appearance with whatever expanded state the items had accumulated.- Parameters:
enabled-trueto hide inline children and route everything through the popover,falseto use the default layout
-
getRootMatchNested
The currentRootMatchNestedmode. Default:RootMatchNested.ONLY_RAIL. SeeRootMatchNestedfor the per-value semantics.- Returns:
- the active
RootMatchNested; nevernull
-
getActiveViewItems
Returns all rail items whose own path (or any of their path aliases) equals the current view's location.Match semantics:
- Path equality only. An item's
matchNestedsetting is deliberately ignored — a parent does not become active just because one of its descendants matches the current view. This mirrors the typical use case (breadcrumbs, page titles): callers want the leaf-most item that owns the displayed view. - Aliases count. Vaadin's client-side
[active]highlight also matches aliases, so server-side answer and visual highlight stay aligned. - Real items only. The internal clones used to populate hover popovers live under
a separate nested
SideNavand are skipped — only items the application actually inserted are returned. - DFS pre-order. Multiple matches (e.g. two items wired to the same path, or a path-vs-alias collision) are returned in DFS pre-order so iteration order is deterministic and tied to insertion order.
The current location is read via
UI.getCurrent().getInternals().getActiveViewLocation(), the same value thatAfterNavigationEvent.getLocation()surfaces. Returns an empty list when there is no currentUI.- Returns:
- all matching rail items in DFS pre-order; empty if none match
- See Also:
- Path equality only. An item's
-
getActiveViewItem
The first match fromgetActiveViewItems(), or empty if no item matches. Convenience accessor for the typical single-match case.- Returns:
- the first matching rail item in DFS pre-order, or empty
-
addRailModeChangedListener
public com.vaadin.flow.shared.Registration addRailModeChangedListener(com.vaadin.flow.component.ComponentEventListener<RailModeChangedEvent> listener) Registers a listener forRailModeChangedEvent. The event fires wheneversetRailMode(boolean)actually changes the state (no-ops don't fire).- Parameters:
listener- the listener to invoke on each rail-mode transition; must not benull- Returns:
- a
Registrationhandle that can be used to remove the listener
-