Skip to main content

rc-app-bar

App bar modeled after the Material 3 Top app bar, with leading, title, center, trailing regions and optional scroll behavior.

Package
@rcarls/rc-app-bar
Element
<rc-app-bar>
Native dependency
Structural slots only; consumer supplies controls, icons, and landmarks
State model
Controlled or uncontrolled scrolled state
Main events
rc-app-bar-scroll

Installation​

npm install @rcarls/rc-app-bar
import '@rcarls/rc-app-bar/define';

Live demo​

Title app bar​

The center slot fills the flexible space between leading and trailing by default, capped by --rc-app-bar-center-max-inline-size before it starts centering within the available space instead of continuing to stretch (the demo above sets a cap so the search field doesn't stretch edge-to-edge). Add center-symmetric when a control must sit at the bar's exact geometric midpoint regardless of asymmetric leading/trailing widths instead:

<rc-app-bar center-symmetric>
<button slot="leading">Long leading label</button>
<rc-search-bar slot="center">...</rc-search-bar>
<button slot="trailing" aria-label="Account">Account</button>
</rc-app-bar>

Theming​

The default demo mode shows the component without a package theme. Use the shared preview controls on this page to compare inherited, light, and dark color schemes or to apply the optional Material theme only inside the demo frames.

Material top app bar sizes are theme presets, not public component variants. Keep the component structural with variant="compact" or variant="expanded", then use rc-theme-material modifier classes to tune the token mapping:

<rc-app-bar class="rc-app-bar--large" variant="expanded" scroll-behavior="collapse">
<button slot="leading" type="button" aria-label="Back">...</button>
<h1>Reading list</h1>
</rc-app-bar>

Available Material helper classes are rc-app-bar--center-aligned, rc-app-bar--medium, and rc-app-bar--large. For custom collapse animation, read the component-owned --rc-app-bar-collapse-progress value in CSS:

rc-app-bar .brand-mark {
opacity: calc(1 - var(--rc-app-bar-collapse-progress, 0));
}

API​

Properties

PropertyMarkupTypeDefaultDescription
variantvariantRCAppBarVariant'compact'Structural variant. `expanded` adds a flexible title row.
centerSymmetriccenter-symmetricbooleanfalseOpt-in: mirrors the leading/trailing edge widths so `slot="center"` content stays exactly viewport-centered regardless of asymmetric side content. Default (absent): center content fills the flexible middle column like a plain title, capped and self-centered within it via `--rc-app-bar-center-max-inline-size` -- centered within the available space between leading and trailing, not mirrored to the viewport.
scrollBehaviorscroll-behaviorRCAppBarScrollBehavior'pinned'Visual response to observed scrolling.
scrollTargetscroll-targetScrollObserverTarget | string | nullnullScroll container to observe. The attribute accepts a CSS selector or `window`; the property also accepts an element, document, or window.
scrollThresholdscroll-thresholdnumber4Scroll offset in px past which the bar is scrolled (strict `>`).
scrolledJS property onlybooleanNot specifiedWhether the bar is past its scroll threshold. Host writes are silent and controlled; assigning `undefined` releases observation.
collapsedJS property onlybooleanNot specifiedWhether the expanded title row is currently collapsed.

Methods

No public methods are documented in the custom elements manifest.

Events

EventDetail typeDescription
rc-app-bar-scrollNo detail type documentedWhen observed scroll state crosses the threshold; `detail: { scrolled }`

Slots

NameDescription
leadingLeading navigation or controls; accepts multiple children
(default)The single title region; may contain title and subtitle markup
centerContent such as search, kept within the flexible middle column between leading and trailing. Fills that column by default, capped and self-centered within it via `--rc-app-bar-center-max-inline-size`; add `center-symmetric` for exact viewport centering regardless of asymmetric leading/trailing content instead.
trailingTrailing action controls

CSS Custom Properties

PropertyDefaultDescription
--rc-app-bar-bgCanvasBar background
--rc-app-bar-colorCanvasTextBar text color
--rc-app-bar-compact-min-height3remCompact row minimum height
--rc-app-bar-expanded-padding-block0.75emExpanded title padding
--rc-app-bar-padding-inline0.75emHorizontal padding
--rc-app-bar-gap0.5emGap between regions
--rc-app-bar-center-max-inline-size100%Max width of `slot="center"` content before it centers within the available space instead of filling it. No effect when `center-symmetric` is set.
--rc-app-bar-title-start-padding0pxExtra title inline-start padding used only when the leading slot is empty (M3: align with content below when there's no navigation icon)
--rc-app-bar-transition-duration200msEndpoint and hide duration
--rc-app-bar-scroll-divider1px solid GrayTextScrolled divider
--rc-app-bar-collapse-progress0Collapse animation progress 0–1; read-only
--rc-app-bar-title-font-sizeNot specifiedCompact-row title font size (opt-in; inherits when unset)
--rc-app-bar-expanded-title-font-sizeNot specifiedExpanded-row title font size (opt-in)

CSS Parts

PartDescription
rootThe grid container
leadingWrapper around the leading slot
titleWrapper around the single title slot
centerWrapper around the centered slot
trailingWrapper around the trailing slot
scroll-shadowScrolled-state separator