Class SideNavItem
java.lang.Object
com.vaadin.flow.component.Component
com.vaadin.flow.component.sidenav.SideNavItem
- All Implemented Interfaces:
AttachNotifier,DetachNotifier,HasElement,HasStyle,HasPrefix,HasSuffix,Serializable
@Tag("vaadin-side-nav-item")
@NpmPackage(value="@vaadin/side-nav",
version="24.1.10")
@JsModule("@vaadin/side-nav/src/vaadin-side-nav-item.js")
public class SideNavItem
extends Component
implements HasPrefix, HasSuffix
A menu item for the
SideNav component.
Besides the target path it can contain a label, prefix and suffix
component, like icons or badges. You can create a hierarchical navigation
structure by adding other SideNavItem instances to this
SideNavItem instance via addItem(SideNavItem...).
- Author:
- Vaadin Ltd
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionSideNavItem(String label) Creates a menu item which does not link to any view but only shows the given label.SideNavItem(String label, Class<? extends Component> view) Creates a new menu item using the given label that links to the given view.SideNavItem(String label, Class<? extends Component> view, Component prefixComponent) Creates a new menu item using the given label and prefix component (like an icon) that links to the given view.SideNavItem(String label, String path) Creates a new menu item using the given label that links to the given path.SideNavItem(String label, String path, Component prefixComponent) Creates a new menu item using the given label and prefix component (like an icon) that links to the given path. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddItem(SideNavItem... items) Adds navigation menu item(s) to the menu.voidaddItemAsFirst(SideNavItem item) Adds the given navigation item as the first child of this navigation item.voidaddItemAtIndex(int index, SideNavItem item) Adds the given item as child of this navigation item at the specific index.protected FeatureFlagsGets the feature flags for the current UI.getItems()Gets the items added to this navigation item (the children of this component that are instances ofSideNavItem).getLabel()Gets the label of this menu item.getPath()Gets the path this navigation item links to.booleanReturns whether the side navigation menu item is expanded or collapsed.protected voidonAttach(AttachEvent attachEvent) Called when the component is attached to a UI.voidremove(SideNavItem... items) Removes the menu item(s) from the menu.voidRemoves all navigation menu items from this item.voidsetExpanded(boolean expanded) Sets the expanded status of the item.voidSet a textual label for the item.voidSets the view this item links to.voidSets the path in a form or a URL string this navigation item links to.protected voidsetupSideNavItem(SideNavItem item) Implement this method to set up/modify the SideNavItem right before it's added to the list of the navigation items.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, onDetach, 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.shared.HasPrefix
getPrefixComponent, setPrefixComponentMethods 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, setSuffixComponent
-
Constructor Details
-
SideNavItem
Creates a menu item which does not link to any view but only shows the given label.- Parameters:
label- the label for the item
-
SideNavItem
Creates a new menu item using the given label that links to the given path.- Parameters:
label- the label for the itempath- the path to link to
-
SideNavItem
Creates a new menu item using the given label that links to the given view.- Parameters:
label- the label for the itemview- the view to link to
-
SideNavItem
Creates a new menu item using the given label and prefix component (like an icon) that links to the given path.- Parameters:
label- the label for the itempath- the path to link toprefixComponent- the prefix component for the item (usually an icon)
-
SideNavItem
Creates a new menu item using the given label and prefix component (like an icon) that links to the given view.- Parameters:
label- the label for the itemview- the view to link toprefixComponent- the prefixComponent for the item (usually an icon)
-
-
Method Details
-
getLabel
Gets the label of this menu item.- Returns:
- the label or null if no label has been set
-
setLabel
Set a textual label for the item.The label is also available for screen reader users.
- Parameters:
label- the label text to set; or null to remove the label
-
setPath
Sets the path in a form or a URL string this navigation item links to. Note that there is also an alternative way of how to set the link path viasetPath(Class).- Parameters:
path- The path to link to. Set to null to disable navigation for this item.- See Also:
-
setPath
Sets the view this item links to.Note: Vaadin Router will be used to determine the URL path of the view and this URL will be then set to this navigation item using
setPath(String)- Parameters:
view- The view to link to. The view should be annotated with theRouteannotation. Set to null to disable navigation for this item.- See Also:
-
getPath
Gets the path this navigation item links to.- Returns:
- path this navigation item links to
-
setExpanded
public void setExpanded(boolean expanded) Sets the expanded status of the item.- Parameters:
expanded- true to expand the item, false to collapse it
-
isExpanded
Returns whether the side navigation menu item is expanded or collapsed.- Returns:
- true if the item is expanded, false if collapsed
-
onAttach
Description copied from class:ComponentCalled when the component is attached to a UI.The default implementation does nothing.
This method is invoked before the
AttachEventis fired for the component. -
getFeatureFlags
Gets the feature flags for the current UI.Extracted with protected visibility to support mocking
- Returns:
- the current set of feature flags
-
getItems
Gets the items added to this navigation item (the children of this component that are instances ofSideNavItem). This doesn't include the items added to the children of this navigation item.- Returns:
- the child
SideNavIteminstances in this navigation menu - See Also:
-
removeAll
public void removeAll()Removes all navigation menu items from this item.