Class SideNavItem
- All Implemented Interfaces:
AttachNotifier
,DetachNotifier
,HasElement
,HasEnabled
,HasStyle
,HasPrefix
,HasSuffix
,Serializable
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, Class<? extends Component> view, RouteParameters routeParameters) Creates a new menu item using the given label that links to the given view.SideNavItem
(String label, Class<? extends Component> view, RouteParameters routeParameters, 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.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.Gets the path aliases for this item.Gets the target of this item.boolean
Returns whether the side navigation menu item is expanded or collapsed.boolean
Gets whether this item also matches nested paths / routes.boolean
Gets whether the target URL should be opened in a new browser tab.boolean
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
setMatchNested
(boolean value) Sets whether to also match nested paths / routes.void
setOpenInNewBrowserTab
(boolean openInNewBrowserTab) Sets whether the target URL should be opened in a new browser tab.void
RetrievesRoute
andRouteAlias
annotations from the specified view, and then sets the corresponding path and path aliases for this item.void
setPath
(Class<? extends Component> view, RouteParameters routeParameters) RetrievesRoute
andRouteAlias
annotations from the specified view, and then sets the corresponding path and path aliases for this item.void
Sets the path in a form or a URL string this navigation item links to.void
setPathAliases
(Set<String> pathAliases) Sets the specified path aliases to this item.void
setQueryParameters
(QueryParameters queryParameters) Sets theQueryParameters
of this item.void
setRouterIgnore
(boolean ignore) The routing mechanism in Vaadin by default intercepts all side nav items with a relative URL.void
Where to display the linked URL, as the name for a browsing context.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, onAttach, 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.HasEnabled
isEnabled, setEnabled
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 that links to the given view.- Parameters:
label
- the label for the itemrouteParameters
- the route parametersview
- 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)
-
SideNavItem
public SideNavItem(String label, Class<? extends Component> view, RouteParameters routeParameters, Component prefixComponent) 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 torouteParameters
- the route parametersprefixComponent
- 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
RetrievesRoute
andRouteAlias
annotations from the specified view, and then sets the corresponding path and path aliases for this item.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:
-
setPath
RetrievesRoute
andRouteAlias
annotations from the specified view, and then sets the corresponding path and path aliases for this item.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.routeParameters
- the route parameters- See Also:
-
getPath
Gets the path this navigation item links to.- Returns:
- path this navigation item links to
-
setQueryParameters
Sets theQueryParameters
of this item.The query string will be generated from
QueryParameters.getQueryString()
and will be appended to thepath
attribute of this item.- Parameters:
queryParameters
- the query parameters object, ornull
to remove existing query parameters
-
getPathAliases
Gets the path aliases for this item.- Returns:
- the path aliases for this item, empty if none
-
setPathAliases
Sets the specified path aliases to this item. The aliases act as secondary paths when determining the active state of the item.Note that it is allowed to pass
null
as value to clear the selection.- Parameters:
pathAliases
- the path aliases to set to this item
-
getTarget
Gets the target of this item.- Returns:
- the target of this item
-
setTarget
Where to display the linked URL, as the name for a browsing context.The following keywords have special meanings for where to load the URL:
_self
: the current browsing context. (Default)_blank
: usually a new tab, but users can configure browsers to open a new window instead._parent
: the parent browsing context of the current one. If no parent, behaves as_self
._top
: the topmost browsing context (the "highest" context that?s an ancestor of the current one). If no ancestors, behaves as_self
.
- Parameters:
target
- the target of this item
-
isMatchNested
public boolean isMatchNested()Gets whether this item also matches nested paths / routes.- Returns:
- true if this item also matches nested paths / routes, false otherwise
-
setMatchNested
public void setMatchNested(boolean value) Sets whether to also match nested paths / routes.false
by default.When enabled, an item with the path
/path
is considered current when the browser URL is/path
,/path/child
,/path/child/grandchild
, etc.Note that this only affects matching of the URLs path, not the base origin or query parameters.
- Parameters:
value
- true to also match nested paths / routes, false otherwise
-
isRouterIgnore
public boolean isRouterIgnore()- Returns:
- true if this item should be ignored by the Vaadin router and behave like a regular anchor.
-
setRouterIgnore
public void setRouterIgnore(boolean ignore) The routing mechanism in Vaadin by default intercepts all side nav items with a relative URL. This method can be used to make the router ignore this item. This makes it behave like a regular anchor, causing a full page load.- Parameters:
ignore
- true if this item should not be intercepted by the single-page web application routing mechanism in Vaadin.
-
setOpenInNewBrowserTab
public void setOpenInNewBrowserTab(boolean openInNewBrowserTab) Sets whether the target URL should be opened in a new browser tab.This is a convenience method for setting the target to
_blank
. SeesetTarget(String)
for more information.- Parameters:
openInNewBrowserTab
- true if the target URL should be opened in a new browser tab, false otherwise
-
isOpenInNewBrowserTab
public boolean isOpenInNewBrowserTab()Gets whether the target URL should be opened in a new browser tab.- Returns:
- true if the target URL should be opened in a new browser tab, false otherwise
-
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
-
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
SideNavItem
instances in this navigation menu - See Also:
-
removeAll
public void removeAll()Removes all navigation menu items from this item.