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 selectsvaadin-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
Popoveron first attach. The popover's hover-trigger eligibility is gated by the owningSideNavRail'sPopoverOnand rail state — seeSideNavRail.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
ConstructorsConstructorDescriptionSideNavRailItem(String label) 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.SideNavRailItem(String label, String path) 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 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) Optional<com.vaadin.flow.component.popover.Popover> Returns the popover of this item, if one has been created.protected voidonAttach(com.vaadin.flow.component.AttachEvent event) protected voidonDetach(com.vaadin.flow.component.DetachEvent event) voidremove(com.vaadin.flow.component.sidenav.SideNavItem... items) voidvoidvoidsetPrefixComponent(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, setTargetMethods 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.HasEnabled
isEnabled, setEnabledMethods inherited from interface com.vaadin.flow.component.shared.HasPrefix
getPrefixComponentMethods inherited from interface com.vaadin.flow.component.sidenav.HasSideNavItems
getItemsMethods inherited from interface com.vaadin.flow.component.HasStyle
addClassName, addClassNames, getClassName, getClassNames, getStyle, hasClassName, removeClassName, removeClassNames, setClassName, setClassNameMethods inherited from interface com.vaadin.flow.component.shared.HasSuffix
getSuffixComponent, setSuffixComponentMethods inherited from interface com.vaadin.flow.component.shared.HasTooltip
getTooltip, setTooltipText
-
Constructor Details
-
SideNavRailItem
Non-navigating container item. Click does nothing; useful as a parent for children.- Parameters:
label- the visible label of the item; may benullfor an unlabelled item, in which case the rail-mode letter-avatar fallback is suppressed
-
SideNavRailItem
Item navigating to the given path (server- or client-side route).- Parameters:
label- the visible label of the item; may benullpath- the route path the item navigates to on click; may benullfor a non-navigating item
-
SideNavRailItem
Item navigating to the given Flow route class.- Parameters:
label- the visible label of the item; may benullview- the Flow view class the item navigates to on click; must not benull
-
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 benullpath- the route path the item navigates to on click; may benullfor a non-navigating itemprefixComponent- the component rendered to the left of the label (typically aVaadinIconor anAvatar); may benull, 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 benullview- the Flow view class the item navigates to on click; must not benullprefixComponent- the component rendered to the left of the label (typically aVaadinIconor anAvatar); may benull, in which case the rail-mode letter-avatar fallback kicks in
-
-
Method Details
-
setLabel
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 (seeensureLetterAvatar()) so it matches the new label's first letter. Idempotent across repeated calls.- Overrides:
setLabelin classcom.vaadin.flow.component.sidenav.SideNavItem- Parameters:
label- the new label text; may benull
-
setPrefixComponent
public void setPrefixComponent(com.vaadin.flow.component.Component prefix) Overridden so that setting the prefix back to
nullre-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 aVaadinIconor anAvatar); passnullto fall back to the auto-generated letter avatar
-
removeAll
public void removeAll()The popover (if any) is rebuilt with no children.
-
onAttach
protected void onAttach(com.vaadin.flow.component.AttachEvent event) - Overrides:
onAttachin classcom.vaadin.flow.component.Component
-
onDetach
protected void onDetach(com.vaadin.flow.component.DetachEvent event) - Overrides:
onDetachin classcom.vaadin.flow.component.Component
-
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'sRailTooltipModeisPOPOVER_HEADERand rail-mode is active (seeSideNavRail.isLeafPopoverActive()). Items that have not been attached yet, or that are not part of a rail, returnOptional.empty().- Returns:
- an
Optionalcontaining the underlyingPopover, orOptional.empty()if none has been created
-