Class AppHeadroom
- All Implemented Interfaces:
com.vaadin.flow.component.AttachNotifier, com.vaadin.flow.component.DetachNotifier, com.vaadin.flow.component.HasElement, com.vaadin.flow.component.HasStyle, Serializable
AppLayout's top and bottom navigation bars on scroll.
This component only ever knows about AppLayout's own standard,
public contract — specifically the navbar-top and navbar-bottom
shadow-DOM parts every vaadin-app-layout instance exposes, regardless
of subclass. It has no knowledge of, and no dependency on, any specific
AppLayout extension (e.g. one that adds a persistent side rail):
whatever a subclass does with those two standard parts, AppHeadroom
finds and manages them the same way every time.
By default, a bar that's already pinned to the viewport
(position: fixed) and shaped like a vertical rail rather than a
horizontal bar (taller than wide) is left alone automatically — a plain,
observable geometry fact, not something any extension has to declare. For
cases where that inference isn't right (or an extension's own behavior can't
be reliably inferred that way), setTopBarCollapsible(boolean) / setBottomBarCollapsible(boolean) let calling code state it explicitly instead. See
those methods for how this is meant to be wired up from application code.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classFired whenever the chrome's expanded/collapsed state changes, whether driven by scrolling on the client or by a server-initiated reset (e.g. detaching this instance viaremove()).static final classOne bar's condensed-view accessor (seegetCondensedTop()/getCondensedBottom()) — pick a shape viaAppHeadroom.CondensedBar.asFloating()orAppHeadroom.CondensedBar.asRibbon()to get a shape-specific accessor exposing only the methods that make sense for it, the same patternGrid'sasSingleSelect()/asMultiSelect()already use for an analogous "pick one of a few mutually-exclusive modes" choice.static enumCoarse device category, used bysetActivationPredicate(SerializableBiPredicate).static final classAppHeadroom.CondensedBar.asFloating()'s shape-specific accessor.static enumViewport orientation, used bysetActivationPredicate(SerializableBiPredicate).static classDeprecated.static final classAppHeadroom.CondensedBar.asRibbon()'s shape-specific accessor. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringWire name of thesetBottomBarCollapsible(boolean)attribute.static final StringWire name of the attribute telling app-headroom.ts which shape (if any) the bottom condensed view is.static final StringWire name of the attribute telling app-headroom.ts which shape (if any) the top condensed view is.static final StringWire name of thesetHideTolerance(int)attribute.static final StringWire name of thesetShowTolerance(int)attribute.static final StringWire name of thesetTopBarCollapsible(boolean)attribute.static final StringWire name of thesetTopOffset(int)attribute.static final StringWire name of thesetTransitionDuration(int)attribute.static final StringWire name of theaddCollapseChangeListener(ComponentEventListener)DOM event.static final StringWire name of theisActive()element property.static final StringWire name of theisCollapsed()element property.static final Stringstatic final Stringstatic final Stringslotname the bottom condensed view's element is attached under.static final Stringslotname the top condensed view's element is attached under. -
Method Summary
Modifier and TypeMethodDescriptioncom.vaadin.flow.shared.RegistrationaddCollapseChangeListener(com.vaadin.flow.component.ComponentEventListener<AppHeadroom.CollapseChangeEvent> listener) Registers a listener to be notified wheneverisCollapsed()changes.com.vaadin.flow.shared.RegistrationaddPinnedChangeListener(com.vaadin.flow.component.ComponentEventListener<AppHeadroom.PinnedChangeEvent> listener) Deprecated.UseaddCollapseChangeListener(ComponentEventListener)instead.static AppHeadroomapplyTo(com.vaadin.flow.component.applayout.AppLayout layout) Applies headroom scroll-hide/show behavior to the given AppLayout and returns the component for optional further configuration.Same asgetCondensedTop(), for the bottom bar.The top bar's condensed-view accessor — a small alternate view that can cross-fade into place while the real top bar is scroll-hidden.booleanisActive()Whether the headroom effect is currently active for this session, per the last evaluation of theactivation predicate.booleanWhether the chrome is currently collapsed/hidden (true) or expanded/shown (false, the initial and default state).booleanisPinned()Deprecated.UseisCollapsed()instead — note the inverted return value:isPinned()(shown) is equivalent to!isCollapsed().protected voidonDetach(com.vaadin.flow.component.DetachEvent detachEvent) Resets the server-visible expanded state directly, rather than relying on the client's ownpinned-changedevent during teardown: when detachment is server-initiated (e.g.voidremove()Detaches this instance, removing its scroll-hide/show behavior from theAppLayoutit was applied to.setActivationPredicate(com.vaadin.flow.function.SerializableBiPredicate<AppHeadroom.DeviceType, AppHeadroom.Orientation> predicate) Sets the predicate that decides whether the headroom effect should be active, evaluated against this session's detectedAppHeadroom.DeviceTypeand currentAppHeadroom.Orientation.setBottomBarCollapsible(boolean collapsible) Same assetTopBarCollapsible(boolean), for the bottom bar.setBottomBarPinned(boolean pinned) Deprecated.UsesetBottomBarCollapsible(boolean)instead — seesetTopBarPinned(boolean)for the argument-inversion note.setHideTolerance(int px) Sets how far, in pixels, the user must scroll down past the last shown-position high-water mark before the chrome hides (default30).setShowTolerance(int px) Sets how far, in pixels, the user must scroll up past the last hidden-position low-water mark before the chrome is restored (default30).setTabletMinShortSidePx(int px) Overrides the physical-screen-shorter-side threshold, in CSS pixels, used to distinguishAppHeadroom.DeviceType.TABLETfromAppHeadroom.DeviceType.PHONEamong touch devices (default768, matchingvaadin-flow-app-nav-layout's equivalent device detection).setTopBarCollapsible(boolean collapsible) Explicitly overrides whether the top bar can ever collapse (hide) at all, regardless of the automatic position/shape inference.setTopBarPinned(boolean pinned) Deprecated.UsesetTopBarCollapsible(boolean)instead — note the inverted argument:setTopBarPinned(true)(never collapse) is equivalent tosetTopBarCollapsible(false).setTopOffset(int px) Sets the distance from the top of the page, in pixels, within which the chrome is always shown (default100).setTransitionDuration(int ms) Sets how long, in milliseconds, the show/hide slide and padding transitions take (default600).Methods 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, onAttach, 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.HasStyle
addClassName, addClassNames, bindClassName, bindClassNames, getClassName, getClassNames, getStyle, hasClassName, removeClassName, removeClassNames, setClassName, setClassName
-
Field Details
-
ATTR_TOP_OFFSET
-
ATTR_HIDE_TOLERANCE
Wire name of thesetHideTolerance(int)attribute.- See Also:
-
ATTR_SHOW_TOLERANCE
Wire name of thesetShowTolerance(int)attribute.- See Also:
-
ATTR_TOP_BAR_PINNED
Wire name of thesetTopBarCollapsible(boolean)attribute.- See Also:
-
ATTR_BOTTOM_BAR_PINNED
Wire name of thesetBottomBarCollapsible(boolean)attribute.- See Also:
-
PROPERTY_PINNED
Wire name of theisCollapsed()element property.- See Also:
-
PROPERTY_ACTIVE
-
EVENT_PINNED_CHANGED
Wire name of theaddCollapseChangeListener(ComponentEventListener)DOM event.- See Also:
-
ATTR_TRANSITION_DURATION
Wire name of thesetTransitionDuration(int)attribute.- See Also:
-
SLOT_CONDENSED_TOP
slotname the top condensed view's element is attached under.- See Also:
-
SLOT_CONDENSED_BOTTOM
slotname the bottom condensed view's element is attached under.- See Also:
-
ATTR_CONDENSED_TOP_SHAPE
Wire name of the attribute telling app-headroom.ts which shape (if any) the top condensed view is.- See Also:
-
ATTR_CONDENSED_BOTTOM_SHAPE
Wire name of the attribute telling app-headroom.ts which shape (if any) the bottom condensed view is.- See Also:
-
SHAPE_FLOATING
ATTR_CONDENSED_TOP_SHAPE/ATTR_CONDENSED_BOTTOM_SHAPEvalue forAppHeadroom.CondensedBar.asFloating().- See Also:
-
SHAPE_RIBBON
- See Also:
-
-
Method Details
-
applyTo
Applies headroom scroll-hide/show behavior to the given AppLayout and returns the component for optional further configuration.The returned instance attaches itself as a peer under the current
UI's root element, never as a light-DOM child oflayout— so it never shows up inlayout.getChildren(). This happens automatically wheneverlayoutitself is attached (immediately, if it already is), and followslayoutacross any subsequent detach/re-attach. Callremove()to detach headroom behavior fromlayoutwithout affecting the layout itself.The effect is active on every device by default; see
setActivationPredicate(SerializableBiPredicate)to restrict it by device type/orientation. -
remove
public void remove()Detaches this instance, removing its scroll-hide/show behavior from theAppLayoutit was applied to. Has no effect if already detached. -
setTopOffset
Sets the distance from the top of the page, in pixels, within which the chrome is always shown (default100). Returnsthisfor chaining.- Throws:
IllegalArgumentException- ifpxis negative
-
setHideTolerance
Sets how far, in pixels, the user must scroll down past the last shown-position high-water mark before the chrome hides (default30). Returnsthisfor chaining.- Throws:
IllegalArgumentException- ifpxis negative
-
setShowTolerance
Sets how far, in pixels, the user must scroll up past the last hidden-position low-water mark before the chrome is restored (default30). Returnsthisfor chaining.- Throws:
IllegalArgumentException- ifpxis negative
-
setTransitionDuration
Sets how long, in milliseconds, the show/hide slide and padding transitions take (default600). Returnsthisfor chaining.- Throws:
IllegalArgumentException- ifmsis negative
-
getCondensedTop
The top bar's condensed-view accessor — a small alternate view that can cross-fade into place while the real top bar is scroll-hidden. Shape it withAppHeadroom.CondensedBar.asFloating()orAppHeadroom.CondensedBar.asRibbon()before supplying content; neither is configured by default, so nothing shows while hidden, same as before this feature existed.Fades on scroll position alone, the same as the real bar. The one thing that suppresses it: an explicit
setTopBarCollapsible(boolean)(false)— a deliberate "never hide this" declaration from application code. The automatic pinned-rail geometry check that can similarly keep the real bar from ever hiding does not also suppress this — that check has no way to know whether a permanently-visible real bar and an app-supplied condensed view are related at all, so it only ever affects the real bar's own slide-away. -
getCondensedBottom
Same asgetCondensedTop(), for the bottom bar. -
setTopBarCollapsible
Explicitly overrides whether the top bar can ever collapse (hide) at all, regardless of the automatic position/shape inference.falsemeans "never collapse this" — also suppressesgetCondensedTop()'s condensed view, unlike the automatic inference, which only ever affects the real bar.Not called directly by any
AppLayoutextension — extensions have no reason to knowAppHeadroomexists. Instead, this is meant to be wired up from application code that already explicitly combines anAppLayoutextension withAppHeadroom(for example, code overriding an extension's own hook for observing layout-mode changes, if it has one), reacting to whatever that extension's own public API exposes about its current state and calling this method accordingly. -
setBottomBarCollapsible
Same assetTopBarCollapsible(boolean), for the bottom bar. -
setTopBarPinned
Deprecated.UsesetTopBarCollapsible(boolean)instead — note the inverted argument:setTopBarPinned(true)(never collapse) is equivalent tosetTopBarCollapsible(false). Calling this delegates tosetTopBarCollapsible(boolean). -
setBottomBarPinned
Deprecated.UsesetBottomBarCollapsible(boolean)instead — seesetTopBarPinned(boolean)for the argument-inversion note. Calling this delegates tosetBottomBarCollapsible(boolean). -
isCollapsed
@Synchronize("pinned-changed") public boolean isCollapsed()Whether the chrome is currently collapsed/hidden (true) or expanded/shown (false, the initial and default state). Kept in sync with the client's own scroll-driven expand/collapse state; seeaddCollapseChangeListener(ComponentEventListener)to be notified of changes instead of polling this. -
isPinned
Deprecated.UseisCollapsed()instead — note the inverted return value:isPinned()(shown) is equivalent to!isCollapsed(). -
addCollapseChangeListener
public com.vaadin.flow.shared.Registration addCollapseChangeListener(com.vaadin.flow.component.ComponentEventListener<AppHeadroom.CollapseChangeEvent> listener) Registers a listener to be notified wheneverisCollapsed()changes. -
addPinnedChangeListener
@Deprecated(since="25.1.1") public com.vaadin.flow.shared.Registration addPinnedChangeListener(com.vaadin.flow.component.ComponentEventListener<AppHeadroom.PinnedChangeEvent> listener) Deprecated.UseaddCollapseChangeListener(ComponentEventListener)instead. -
onDetach
protected void onDetach(com.vaadin.flow.component.DetachEvent detachEvent) Resets the server-visible expanded state directly, rather than relying on the client's ownpinned-changedevent during teardown: when detachment is server-initiated (e.g.layout.remove(headroom)), Flow stops routing further client events for this component the moment removal begins, so the client-fired event fromdisconnectedCallback()never reaches here.- Overrides:
onDetachin classcom.vaadin.flow.component.Component
-
setActivationPredicate
public AppHeadroom setActivationPredicate(com.vaadin.flow.function.SerializableBiPredicate<AppHeadroom.DeviceType, AppHeadroom.Orientation> predicate) Sets the predicate that decides whether the headroom effect should be active, evaluated against this session's detectedAppHeadroom.DeviceTypeand currentAppHeadroom.Orientation. Re-evaluated automatically whenever either becomes known or changes (e.g. on device rotation) — there's nothing further to wire up.The default predicate always returns
true: the effect is active on every device unless this is called. There's no separate plain on/off switch — force it fully on or off yourself with(deviceType, orientation) -> true/-> false, or restrict it by device, e.g. to restore the original phone-always/tablet-landscape-only behavior this had before being extracted into this library:AppHeadroom.applyTo(layout).setActivationPredicate((deviceType, orientation) -> deviceType == AppHeadroom.DeviceType.PHONE || (deviceType == AppHeadroom.DeviceType.TABLET && orientation == AppHeadroom.Orientation.LANDSCAPE));- Returns:
- this, for chaining
-
setTabletMinShortSidePx
Overrides the physical-screen-shorter-side threshold, in CSS pixels, used to distinguishAppHeadroom.DeviceType.TABLETfromAppHeadroom.DeviceType.PHONEamong touch devices (default768, matchingvaadin-flow-app-nav-layout's equivalent device detection).Must be called before the target
AppLayoutattaches to take effect — device type is detected once, at first attach, same assetActivationPredicate(SerializableBiPredicate)'s predicate is evaluated against whatever's known at the time.- Returns:
- this, for chaining
- Throws:
IllegalArgumentException- ifpxis negative
-
isActive
public boolean isActive()Whether the headroom effect is currently active for this session, per the last evaluation of theactivation predicate. Defaults totrueuntil device type and orientation are both known (shortly after the targetAppLayoutattaches).
-
AppHeadroom.CollapseChangeEventinstead.