com.vaadin.flow.component.sidenav.
Class SideNavItem
All Implemented Interfaces:
AttachNotifier
, DetachNotifier
, HasElement
, HasStyle
, HasPrefix
, HasSuffix
, Serializable
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 TypeMethodDescriptionvoid
addItem
(SideNavItem... items) Adds navigation menu item(s) to the menu.
void
addItemAsFirst
(SideNavItem item) Adds the given navigation item as the first child of this navigation item.
void
addItemAtIndex
(int index, SideNavItem item) Adds the given item as child of this navigation item at the specific index.
protected FeatureFlags
Gets the feature flags for the current UI.
getItems()
Gets the items added to this navigation item (the children of this component that are instances of
SideNavItem
).getLabel()
Gets the label of this menu item.
getPath()
Gets the path this navigation item links to.
boolean
Returns whether the side navigation menu item is expanded or collapsed.
protected void
onAttach
(AttachEvent attachEvent) Called when the component is attached to a UI.
void
remove
(SideNavItem... items) Removes the menu item(s) from the menu.
void
Removes all navigation menu items from this item.
void
setExpanded
(boolean expanded) Sets the expanded status of the item.
void
Set a textual label for the item.
void
Sets the view this item links to.
void
Sets the path in a form or a URL string this navigation item links to.
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.
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, 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.shared.HasPrefix
getPrefixComponent, setPrefixComponent
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
-
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 via
setPath(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 theRoute
annotation. 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:
Component
Called when the component is attached to a UI.
The default implementation does nothing.
This method is invoked before the
AttachEvent
is 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 of
SideNavItem
). This doesn't include the items added to the children of this navigation item.Returns:
the child
SideNavItem
instances in this navigation menuSee Also:
-
removeAll
public void removeAll()Removes all navigation menu items from this item.