Class AppNavLayout
- All Implemented Interfaces:
com.vaadin.flow.component.AttachNotifier, com.vaadin.flow.component.DetachNotifier, com.vaadin.flow.component.HasElement, com.vaadin.flow.component.HasStyle, com.vaadin.flow.router.AfterNavigationObserver, com.vaadin.flow.router.internal.AfterNavigationHandler, com.vaadin.flow.router.RouterLayout, Serializable
SideNav on desktop.
Subclass, supply a title via super(...), and annotate with
Layout. The DrawerToggle and drawer are wired
automatically; the nav-item content for each of the five device/orientation scenarios
this layout distinguishes — desktop, tablet portrait, tablet landscape, phone portrait, and
phone landscape — is built by an independently pluggable NavRenderer, supplied
lazily since only one scenario is ever relevant to a given session.
See setDesktopNavRenderer(Supplier), setTabletPortraitNavRenderer(Supplier),
setTabletLandscapeNavRenderer(Supplier), setPhonePortraitNavRenderer(Supplier), and
setPhoneLandscapeNavRenderer(Supplier) (plus the setTabletNavRenderer(Supplier)/
setPhoneNavRenderer(Supplier) convenience setters covering both orientations at once),
defaulting to SideNavDrawerNavRenderer (desktop), SideRailNavRenderer
(tablet, both orientations), and TouchBarNavRenderer (phone, both orientations)
respectively. The NavType chrome built for a scenario (rail vs.
bottom bar vs. drawer) is not a separate choice — it's NavRenderer.navType() of
whichever renderer is configured for that scenario, so a scenario's renderer and its chrome
can never disagree with each other.
The active scenario is re-evaluated dynamically on touch devices whenever the viewport size changes (rotation, split-screen resize), switching nav components in place without a page reload.
Use the purpose-named methods to place adaptive content:
addBranding(Component...)— header on desktop, drawer top on mobilesetUserMenu(Component)— header trailing on desktop, drawer bottom on mobile
Override the nav grouping strategy via setNavGrouper(NavGrouper) and the
SideNavItem renderer via setNavNodeRenderer(ComponentRenderer). Changes to any
nav configuration setter take effect immediately, even after attachment.
Per-view header content is assembled automatically on each navigation.
Views implementing HasViewHeaderTitle supply an icon+title component
(desktop only). Views implementing HasViewHeaderComponent supply an
action component shown on both platforms.
addToNavbar(Component...) is preserved as an escape hatch.
All environment-specific values are supplied by the subclass constructor.
Rail mode is built entirely from standard AppLayout constructs.
The rail is AppLayout's own navbar-bottom slot (the same slot
the ordinary touch bottom bar uses), repositioned and restyled via CSS keyed
on the nav-rail attribute this class sets on itself — not a distinct
part of its own. Any companion component that understands
AppLayout's standard navbar-top/navbar-bottom contract
therefore interoperates with rail mode automatically.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class com.vaadin.flow.component.applayout.AppLayout
com.vaadin.flow.component.applayout.AppLayout.AppLayoutI18n, com.vaadin.flow.component.applayout.AppLayout.Section -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedCreates anAppNavLayoutwith the default renderers for each scenario (phone → touch, tablet → rail, desktop → sidenav). -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddBranding(com.vaadin.flow.component.Component... components) Adds brand/identity content.com.vaadin.flow.shared.RegistrationaddNavTypeChangedListener(com.vaadin.flow.component.ComponentEventListener<NavTypeChangedEvent> listener) Adds a listener forNavTypeChangedEvent, fired whenever the activeNavTypeis determined and applied — including on first attachment.voidaddToNavbar(com.vaadin.flow.component.Component... components) Appends components directly to the top bar row.voidafterNavigation(com.vaadin.flow.router.AfterNavigationEvent event) On each navigation: assembles theviewHeaderSlotfrom the current view'sHasViewHeaderTitleandHasViewHeaderComponentif present, and re-invokes the activeNavRenderer(s) so active-item highlighting and drill-down content stay current.protected booleanisMobile()Returnstrueif this session is using touch or rail nav (not desktop SideNav or header tabs).protected voidonAttach(com.vaadin.flow.component.AttachEvent attachEvent) protected voidCalled whenever the activeNavTypeis determined and applied — including on first attachment, not just on later changes.protected voidsetDesktopNavRenderer(Supplier<NavRenderer> renderer) Overrides theNavRendererused for the desktop scenario, constructed at most once, the first time it's actually needed.protected voidsetNavGrouper(NavGrouper grouper) Overrides the nav grouping strategy.protected voidsetNavItemFilter(Predicate<com.vaadin.flow.server.menu.MenuEntry> filter) Overrides the predicate deciding whether a givenMenuEntryappears in the nav tree at all — for hiding a view the current user lacks permission for, one only relevant on certain devices, or for any other reason a view shouldn't be offered as a navigation target right now.protected voidsetNavMatchNested(boolean matchNested) Controls whether desktopSideNavItems use nested-route matching (SideNavItem.setMatchNested(boolean)), which causes a parent item to appear active whenever any of its child routes is current.protected voidsetNavNodeRenderer(com.vaadin.flow.data.renderer.ComponentRenderer<com.vaadin.flow.component.sidenav.SideNavItem, NavNode> renderer) Overrides theSideNavItemrenderer for the desktop side nav.protected voidsetNavPathMatcher(BiPredicate<String, String> matcher) Overrides the predicate used to determine whether the current navigation path belongs to a nav item's section.protected voidsetPhoneLandscapeNavRenderer(Supplier<NavRenderer> renderer) Overrides theNavRendererused for the landscape-phone scenario, constructed at most once, the first time it's actually needed.protected voidsetPhoneNavRenderer(Supplier<NavRenderer> renderer) Overrides theNavRendererused for both phone orientations at once, sharing a single memoized instance between them — equivalent to callingsetPhonePortraitNavRenderer(Supplier)andsetPhoneLandscapeNavRenderer(Supplier)with a shared supplier, not two independent ones.protected voidsetPhonePortraitNavRenderer(Supplier<NavRenderer> renderer) Overrides theNavRendererused for the portrait-phone scenario, constructed at most once, the first time it's actually needed.protected voidsetTabletLandscapeNavRenderer(Supplier<NavRenderer> renderer) Overrides theNavRendererused for the landscape-tablet scenario, constructed at most once, the first time it's actually needed.setTabletMinShortSidePx(int px) Overrides the physical-screen-shorter-side threshold, in CSS pixels, used to distinguishDeviceType.TABLETfromDeviceType.PHONEamong touch devices (default768— the common responsive-design convention for the tablet/phone boundary, matching an iPad's portrait-mode shortest side and Bootstrap'smdbreakpoint).protected voidsetTabletNavRenderer(Supplier<NavRenderer> renderer) Overrides theNavRendererused for both tablet orientations at once, sharing a single memoized instance between them — equivalent to callingsetTabletPortraitNavRenderer(Supplier)andsetTabletLandscapeNavRenderer(Supplier)with a shared supplier, not two independent ones.protected voidsetTabletPortraitNavRenderer(Supplier<NavRenderer> renderer) Overrides theNavRendererused for the portrait-tablet scenario, constructed at most once, the first time it's actually needed.protected voidsetUserMenu(com.vaadin.flow.component.Component userMenu) Sets the user-context widget (avatar, name, account menu).protected voidsetViewIconGenerator(Function<com.vaadin.flow.server.menu.MenuEntry, Supplier<com.vaadin.flow.component.icon.Icon>> generator) Sets the icon generator for leaf nav items.protected voidsetViewNavGroupResolver(Function<com.vaadin.flow.server.menu.MenuEntry, NavGroup> resolver) Sets the nav-group resolver used by the defaultPathPrefixNavGrouper.protected voidsetViewTitleGenerator(Function<com.vaadin.flow.server.menu.MenuEntry, String> generator) Sets the title generator for leaf nav items in the desktopSideNav.Methods inherited from class com.vaadin.flow.component.applayout.AppLayout
addToDrawer, addToNavbar, getContent, getI18n, getPrimarySection, isDrawerOpened, isOverlay, remove, setContent, setDrawerOpened, setI18n, setPrimarySection, showRouterLayoutContentMethods inherited from class com.vaadin.flow.component.Component
addListener, bindVisible, findAncestor, fireEvent, from, get, getChildren, getElement, getEventBus, getId, getListeners, getLocale, getParent, getTestId, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getUI, hasListener, isAttached, isTemplateMapped, isVisible, onDetach, onEnabledStateChanged, removeFromParent, scrollIntoView, scrollIntoView, set, setElement, setId, setTestId, setVisibleMethods inherited from class 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.HasStyle
addClassName, addClassNames, bindClassName, bindClassNames, getClassName, getClassNames, getStyle, hasClassName, removeClassName, removeClassNames, setClassName, setClassNameMethods inherited from interface com.vaadin.flow.router.RouterLayout
removeRouterLayoutContent
-
Constructor Details
-
AppNavLayout
protected AppNavLayout()Creates anAppNavLayoutwith the default renderers for each scenario (phone → touch, tablet → rail, desktop → sidenav).
-
-
Method Details
-
onAttach
protected void onAttach(com.vaadin.flow.component.AttachEvent attachEvent) - Overrides:
onAttachin classcom.vaadin.flow.component.Component
-
addBranding
protected void addBranding(com.vaadin.flow.component.Component... components) Adds brand/identity content. Desktop: placed in the header after theDrawerToggle. Mobile: placed at the top of the navigation drawer. Pass individual components; do not pre-wrap in a layout container. -
setUserMenu
protected void setUserMenu(com.vaadin.flow.component.Component userMenu) Sets the user-context widget (avatar, name, account menu). Desktop: placed trailing in the header. Mobile: placed at the bottom of the navigation drawer. -
setViewIconGenerator
protected void setViewIconGenerator(Function<com.vaadin.flow.server.menu.MenuEntry, Supplier<com.vaadin.flow.component.icon.Icon>> generator) Sets the icon generator for leaf nav items. Returnnullor a supplier returningnullto show no icon.Takes effect via the default
PathPrefixNavGrouper's lambda closure over this field; has no effect ifsetNavGrouper(NavGrouper)has been called with a custom grouper. -
setViewTitleGenerator
protected void setViewTitleGenerator(Function<com.vaadin.flow.server.menu.MenuEntry, String> generator) Sets the title generator for leaf nav items in the desktopSideNav. Returnnullto fall back to@Menu#title().Note: this generator applies to desktop
SideNavItemlabels only. Touch and rail nav item labels always useNavNode.title()(derived from@Menu(title=...)); this generator has no effect on those surfaces. -
isMobile
protected boolean isMobile()Returnstrueif this session is using touch or rail nav (not desktop SideNav or header tabs).Returns
falsebefore the firstonAttach(AttachEvent)completes, because device detection requires a client round-trip. Do not call this from a subclass constructor. -
setTabletMinShortSidePx
Overrides the physical-screen-shorter-side threshold, in CSS pixels, used to distinguishDeviceType.TABLETfromDeviceType.PHONEamong touch devices (default768— the common responsive-design convention for the tablet/phone boundary, matching an iPad's portrait-mode shortest side and Bootstrap'smdbreakpoint).If the layout is already attached, device type is re-evaluated and the nav type re-applied immediately.
- Returns:
- this, for chaining
- Throws:
IllegalArgumentException- ifpxis negative
-