Class SideNavItem
- All Implemented Interfaces:
AttachNotifier,DetachNotifier,HasElement,HasEnabled,HasStyle,HasPrefix,HasSuffix,HasTooltip,HasSideNavItems,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 HasSideNavItems.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 C> view, T parameter) Creates a new menu item using the given label that links to the given view, which must implementHasUrlParameter.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 TypeMethodDescriptiongetLabel()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.booleanReturns whether the side navigation menu item is expanded or collapsed.booleanGets whether this item also matches nested paths / routes.booleanGets whether the target URL should be opened in a new browser tab.booleanvoidsetExpanded(boolean expanded) Sets the expanded status of the item.voidSet a textual label for the item.voidsetMatchNested(boolean value) Sets whether to also match nested paths / routes.voidsetOpenInNewBrowserTab(boolean openInNewBrowserTab) Sets whether the target URL should be opened in a new browser tab.<T,C extends Component & HasUrlParameter<T>>
voidRetrievesRouteandRouteAliasannotations from the specified view, and then sets the corresponding path and path aliases for this item.voidRetrievesRouteandRouteAliasannotations from the specified view, and then sets the corresponding path and path aliases for this item.voidsetPath(Class<? extends Component> view, RouteParameters routeParameters) RetrievesRouteandRouteAliasannotations from the specified view, and then sets the corresponding path and path aliases for this item.voidSets the path in a form or a URL string this navigation item links to.voidsetPathAliases(Set<String> pathAliases) Sets the specified path aliases to this item.voidsetQueryParameters(QueryParameters queryParameters) Sets theQueryParametersof this item.voidsetRouterIgnore(boolean ignore) The routing mechanism in Vaadin by default intercepts all side nav items with a relative URL.voidWhere to display the linked URL, as the name for a browsing context.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, 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
getPrefixComponent, setPrefixComponentMethods inherited from interface com.vaadin.flow.component.sidenav.HasSideNavItems
addItem, addItemAsFirst, addItemAtIndex, getItems, remove, removeAllMethods 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
-
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, which must implementHasUrlParameter.- Type Parameters:
T- the type of the URL parameterC- the type of the view- Parameters:
label- the label for the itemview- the view to link to, must implementHasUrlParameterparameter- the URL parameter for the view
-
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
RetrievesRouteandRouteAliasannotations 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 theRouteannotation. Set to null to disable navigation for this item.- See Also:
-
setPath
public <T,C extends Component & HasUrlParameter<T>> void setPath(Class<? extends C> view, T parameter) RetrievesRouteandRouteAliasannotations 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).- Type Parameters:
T- the type of the URL parameterC- the type of the view- Parameters:
view- The view to link to. The view should be annotated with theRouteannotation and must implementHasUrlParameter. Set to null to disable navigation for this item.parameter- the URL parameter for the view
-
setPath
RetrievesRouteandRouteAliasannotations 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 theRouteannotation. 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 theQueryParametersof this item.The query string will be generated from
QueryParameters.getQueryString()and will be appended to thepathattribute of this item.- Parameters:
queryParameters- the query parameters object, ornullto 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
nullas 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.falseby default.When enabled, an item with the path
/pathis 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
-