Introducing a new way to review your PRs.

Read the announcement

spartan-ng / spartan

Cutting-edge tools powering Angular full-stack development.

View on GitHub

18 documents · Updated Nov 23, 2026

docs / brain-overlay-navigation-and-feedback

Brain overlay, navigation, and feedback primitives

The Brain interaction primitives provide headless building blocks for temporary surfaces, structured navigation, disclosure, progress, and notifications. They keep state, focus behavior, and ARIA links in the behavior layer so a styled layer can define the visual result. See the Brain primitives page for the wider package model and Brain form and selection controls for controls that use these interaction patterns.

Interaction model

Each primitive coordinates a small set of roles such as root, trigger, content, item, and close action. The root owns shared state. Child directives expose that state through attributes and events that a presentation layer can style.

The packages are separate Brain entry points. Each entry point also exports an imports collection that groups the directives needed for an Angular template.

References: libs/…/index.ts• L1-31 libs/…/index.ts• L1-10 libs/…/index.ts• L1-14 libs/…/index.ts• L1-8

Temporary surfaces

Temporary surfaces move attention to content that is not part of the normal page flow. They share a trigger-to-content relationship, controlled open state, dismissal rules, and a close phase that can preserve the surface until exit motion finishes.

The common surface flow connects a user action to an open surface, keeps focus and dismissal under the surface contract, and returns control when the surface closes.

flowchart LR
    Trigger --> Surface[Open surface]
    Surface --> Focus[Manage focus]
    Surface --> Dismiss[Handle Escape or outside input]
    Dismiss --> Closing[Closing phase]
    Closing --> Return[Return result and focus]

Overlay foundation

The overlay is the general temporary-surface primitive. It renders a component or template in a centered position or near an origin, supports a backdrop and scroll policy, and gives the caller a reference for state, close results, and position updates. Its trigger and content directives connect the surface to buttons and templates.

References: libs/…/brn-overlay.ts• L39-205 libs/…/brn-overlay.service.ts• L17-108 libs/…/brn-overlay-ref.ts• L8-153 libs/…/brn-overlay-trigger.ts• L8-44

The overlay handles Escape, outside pointer input, and backdrop input as dismissal requests. Only the active surface accepts the request when surfaces are stacked. The caller can disable dismissal for work that must not be interrupted.

References: libs/…/brn-overlay.service.ts• L165-195 libs/…/brn-overlay-ref.ts• L66-103

Dialog surfaces

The dialog is the structured, modal form of an overlay. It adds dialog semantics, labelled and described content, focus restoration, typed context, and a service path for opening either a component or a template. Declarative dialogs and service-opened dialogs use one shared ID sequence, so each dialog can keep a distinct identity. The dialog reference reports open, closing, and closed phases. It waits for exit motion before final disposal, supports reopening during the close phase, and returns an optional result when the surface closes.

References: libs/…/brn-dialog.ts• L36-204 libs/…/brn-dialog.service.ts• L34-98 libs/…/brn-dialog-id.ts• L1-9 libs/…/brn-dialog-id.spec.ts• L28-44 libs/…/brn-dialog-ref.ts• L9-105 libs/…/brn-dialog-content.ts• L6-21 libs/…/brn-dialog-close.ts• L4-16

Dialog titles and descriptions provide the names and supporting text that assistive technology uses to identify the surface. A close control routes dismissal through the dialog reference instead of treating the content as an ordinary page element.

References: libs/…/brn-dialog-title.ts• L4-14 libs/…/brn-dialog-description.ts• L4-24 libs/…/brn-dialog-close.ts• L4-16

The dialog service connects backdrop, outside-pointer, and Escape events to the dialog reference. A backdrop click closes the dialog that owns that backdrop. Outside-pointer and Escape dismissal respect the overlay stack, so a lower dialog stays protected while a modal surface is above it.

References: libs/…/brn-dialog.service.ts• L108-160 libs/…/brn-dialog.service.spec.ts• L33-72

An alert dialog is the confirmation-focused variant. It uses the dialog contract with the alertdialog role and does not close from outside pointer input by default, which keeps a decision step explicit.

References: libs/…/brn-alert-dialog.ts• L4-20 libs/…/index.ts• L1-22

Anchored surfaces

The popover is an anchored overlay for interactive content that stays near a trigger without taking over the page. The trigger supplies the origin and the surface chooses a position around it. The position can change alignment or offset while the surface is in use.

References: libs/…/brn-popover.ts• L15-75 libs/…/brn-popover-content.ts• L1-10 libs/…/brn-popover-trigger.ts• L5-40

The tooltip is a supplementary label for a trigger that already has an action. It opens on mouse or pen hover and keyboard focus. It ignores touch input, supports text or a template, adds aria-describedby while visible, and uses a preferred placement with viewport-aware fallbacks. Its side offset follows the selected axis, and its content presentation follows the position that the viewport resolves after a flip.

Tooltip timing, position, side offset, and presentation hooks can be set through scoped default options. Nested providers merge their values with the defaults above them, so a styled or application layer can change only the parts it owns. The position model also refreshes when direction or spacing changes and accounts for the mobile visual viewport case that can otherwise shift an anchored label.

References: libs/…/brn-tooltip.ts• L54-66 libs/…/brn-tooltip.ts• L190-267 libs/…/brn-tooltip.ts• L274-303 libs/…/brn-tooltip.ts• L381-424 libs/…/brn-tooltip-position.ts• L3-65 libs/…/brn-tooltip-position.spec.ts• L3-14 libs/…/brn-tooltip-content.ts• L9-55 libs/…/brn-tooltip-group.ts• L4-32 libs/…/brn-tooltip.token.ts• L5-49

The hover card is a richer hover or focus surface for non-essential detail. It keeps the trigger and content connected while the pointer moves between them, delays show and hide actions, and reports the resolved side so a presentation layer can adapt after a position change.

References: libs/…/brn-hover-card.ts• L4-16 libs/…/brn-hover-card-content.service.ts• L172-280 libs/…/brn-hover-card-content.service.ts• L282-367

Edge surfaces

The sheet and drawer are dialog-based surfaces that attach to an edge of the viewport. A sheet supports top, bottom, left, or right placement. A drawer uses the same edge model and adds a handle for pointer drag dismissal.

References: libs/…/brn-sheet.ts• L4-31 libs/…/brn-sheet-content.ts• L10-20 libs/…/brn-drawer.ts• L4-30 libs/…/brn-drawer-content.ts• L10-20

Sheet and drawer content reuse dialog naming, description, overlay, and close behavior. A trigger can set the edge for the surface before it opens, so the selected edge remains part of the surface state.

References: libs/…/brn-sheet-trigger.ts• L5-21 libs/…/brn-sheet-title.ts• L1-9 libs/…/brn-sheet-description.ts• L1-9 libs/…/brn-sheet-overlay.ts• L1-10 libs/…/brn-sheet-close.ts• L1-8 libs/…/brn-drawer-trigger.ts• L5-21 libs/…/brn-drawer-title.ts• L1-9 libs/…/brn-drawer-description.ts• L1-9 libs/…/brn-drawer-overlay.ts• L1-10 libs/…/brn-drawer-close.ts• L1-8

The drawer handle distinguishes a deliberate swipe from a scroll gesture. It closes when the drag has enough speed or crosses the configured close threshold. Otherwise it returns the drawer to its open position.

References: libs/…/brn-drawer-handle.ts• L72-123 libs/…/brn-drawer-handle.ts• L200-243 libs/…/brn-drawer-handle.ts• L251-288

Navigation and disclosure primitives keep related content available without forcing a page change. They differ in whether the user selects a route, searches a list, switches a view, or expands content in place.

The navigation menu coordinates top-level links and trigger-owned panels. It supports horizontal or vertical orientation, hover or click opening, nested panels, direction-aware placement, and a short skip-delay window while the user moves between items. A focus manager provides arrow-key movement and wraps around enabled items.

References: libs/…/brn-navigation-menu.ts• L29-105 libs/…/brn-navigation-menu.ts• L113-169 libs/…/brn-navigation-menu-trigger.ts• L46-167

The menu content stays related to its trigger through IDs and ARIA attributes. Escape returns focus to the trigger. Tab moves through panel items and then returns to the next top-level item or closes the panel.

References: libs/…/brn-navigation-menu-content.service.ts• L63-120 libs/…/brn-navigation-menu-content.service.ts• L167-219 libs/…/brn-navigation-menu-trigger.ts• L226-321

Command menus

The command primitive turns a searchable list into a keyboard-driven selection surface. Its input acts as a combobox for a listbox. The root filters and tracks items. An active-descendant model lets arrow keys move through results without moving DOM focus away from the input.

References: libs/…/brn-command.ts• L33-123 libs/…/brn-command-input.ts• L7-67 libs/…/brn-command-list.ts• L4-25

Tabs

Tabs present one view from a related set while keeping the tab labels available for direct switching. The root owns the active key and activation mode. Triggers expose tab semantics, and content panels link back to their labels. Automatic activation changes the view as focus moves. Manual activation waits for selection.

The tab list manages keyboard focus from the triggers that are currently in the DOM. It follows the focused trigger after a click or programmatic change, which keeps arrow-key movement correct when focus and selection differ in manual mode. It also follows runtime additions, removals, and reordering of triggers.

Long tab lists can use a paginated header. The header keeps the active or focused label visible, enables controls only when more labels exist outside the viewport, and realigns when labels, direction, or available space changes.

References: libs/…/brn-tabs.ts• L6-78 libs/…/brn-tabs-list.ts• L6-57 libs/…/brn-tabs-paginated-list.ts• L79-183 libs/…/brn-tabs-paginated-list.ts• L203-260 libs/…/brn-tabs-trigger.ts• L15-81 libs/…/brn-tabs-content.ts• L4-37 libs/…/brn-tabs.spec.ts• L353-618

Lazy tab content creates its view the first time its tab becomes active. This keeps the tab relationship present while avoiding work for views the user has not opened.

References: libs/…/brn-tabs-content-lazy.ts• L5-32 libs/…/brn-tabs-content.ts• L15-29 libs/…/brn-tabs.spec.ts• L159-230

Accordions

The accordion exposes a set of expandable sections with either one open item or several open items. It manages trigger focus with orientation-aware arrow keys, Home, End, Page Up, and Page Down. Each content region is labelled by its trigger and becomes inert when closed.

References: libs/…/brn-accordion.ts• L40-84 libs/…/brn-accordion.ts• L89-177 libs/…/brn-accordion-content.ts• L5-32

Accordion triggers require a button role and a heading wrapper so the section name and expanded state have a clear accessible structure. The header exposes the current orientation for the presentation layer. The item exposes open and close events for application state that must react to disclosure changes.

References: libs/…/brn-accordion-header.ts• L4-15 libs/…/brn-accordion-trigger.ts• L7-23 libs/…/brn-accordion-trigger.ts• L74-110 libs/…/brn-accordion-item.ts• L17-41

Collapsibles

The collapsible is the smaller disclosure primitive for one independently controlled region. Its trigger toggles the root state. Its content uses aria-controls, an ID, and inert while closed so hidden content does not remain interactive.

References: libs/…/brn-collapsible.ts• L7-45 libs/…/brn-collapsible-trigger.ts• L4-28 libs/…/brn-collapsible-content.ts• L5-35

Status and feedback

Status primitives tell users how work is progressing or what happened after an action. Progress stays tied to a task value. Toasts provide time-limited feedback that does not replace the current page or dialog.

Progress indicators

The progress primitive represents determinate work with a value and maximum or indeterminate work with no current value. It exposes progressbar ARIA values, a percentage or custom value label, and state markers for loading, complete, or indeterminate presentation.

References: libs/…/brn-progress.ts• L6-76 libs/…/brn-progress-indicator.ts• L5-16

Values outside the range from zero through the maximum are rejected. This keeps the semantic value and the visual indicator aligned rather than allowing a styled indicator to show a misleading state.

References: libs/…/brn-progress.ts• L51-73

Toast notifications

The Sonner toaster presents short notifications in one or more viewport positions. The shared toast state supports ordinary messages, typed status messages, loading states, promise outcomes, custom components, actions, and cancellation. A toast can be updated by ID instead of creating a second notification.

References: libs/…/state.ts• L6-59 libs/…/state.ts• L62-152 libs/…/types.ts• L5-15

The toaster limits visible items, expands while the user interacts, pauses auto-close during focus or pointer interaction, and exposes a keyboard shortcut to focus the notification area. Toasts use polite live output by default and assertive output when marked important.

References: libs/…/brn-toaster.ts• L32-115 libs/…/brn-toaster.ts• L129-195 libs/…/brn-toast.ts• L23-51 libs/…/brn-toast.ts• L275-352

Loading toasts remain active until the related promise reports success or failure. Dismissible toasts can close through a button, an action, or a swipe. The promise path can replace the loading message with a result message or remove it when no result message is configured.

References: libs/…/state.ts• L86-145 libs/…/brn-toast.ts• L354-429

Accessibility contract

The primitives make the behavioral parts of accessibility part of the component contract. They assign roles, connect labels and panels with IDs, move focus through composite widgets, and mark closed regions as unavailable to interaction.

Use the primitive that matches the user task rather than treating all temporary content as the same surface:

  • Use a dialog for a focused task that needs a labelled surface and controlled dismissal.
  • Use an alert dialog when the user must confirm or cancel a consequential action.
  • Use a popover for interactive content anchored to a trigger.
  • Use a tooltip only for supplementary information about an existing action. Use a popover when touch users must open the content.
  • Use a sheet or drawer when the same focused task should enter from a viewport edge.
  • Use a toast for brief status or result feedback that should not interrupt the current task.

The components expose state through ARIA attributes and data-* markers. The visual layer must preserve the trigger and content relationships. It must not make a closed region interactive only by changing its appearance.

References: libs/…/brn-dialog-content.ts• L6-21 libs/…/brn-dialog-title.ts• L4-14 libs/…/brn-tooltip-content.ts• L9-18 libs/…/brn-tooltip-position.ts• L45-65 libs/…/brn-popover-trigger.ts• L5-14 libs/…/brn-tabs-trigger.ts• L15-31 libs/…/brn-collapsible-content.ts• L5-13

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep the open, closing, and closed contract aligned between the root, reference, trigger, content, and styled layer. A state change that loses the closing phase can cut off exit motion or leave stale overlay content.
  • Preserve ID and ARIA pairings when changing trigger or content structure. Dialog labels, tab panels, accordion regions, navigation panels, command listboxes, and collapsible content depend on those links.
  • Keep declarative and service-opened dialogs on the shared unique-ID contract. Explicit IDs must remain unique across open dialogs.
  • Keep dismissal ownership aligned with the overlay stack. Changes to outside, backdrop, or Escape handling must still protect nested surfaces and their trigger-origin clicks.
  • When changing sheet or drawer direction, keep the trigger override, content side state, overlay placement, and styled edge behavior aligned.
  • When changing toast state or toast types, keep promise updates, ID replacement, live-region priority, timer behavior, and visible-position filtering consistent.
  • When changing orientation or direction, check both focus movement and overlay placement. Horizontal and vertical menus, tabs, accordions, sheets, and drawers expose direction-sensitive behavior.
  • When changing tab registration or keyboard focus, keep the focus manager aligned with the live DOM order. In manual activation mode, keep focused and selected tabs independent.
  • When changing tooltip defaults, preserve the parent-scope merge so a local provider does not erase defaults supplied by an outer application or styled layer.
  • When changing tooltip placement or offset, keep preferred positions, fallback order, resolved arrow state, and right-to-left behavior aligned.

Important failure modes

TriggerConsequenceGuard
A dialog or overlay closes through a path that bypasses its referenceThe content may disappear without the expected result, state event, or exit phaseRoute programmatic and user dismissal through the surface reference or root state
Two dialogs use the same explicit IDThe later dialog cannot open because dialog identities must be uniqueUse the shared generated ID path or assign a unique explicit ID
A lower dialog handles outside or Escape dismissal while a modal dialog is above itThe wrong surface closes and the user loses the active taskApply the overlay-stack check before outside-pointer and Escape dismissal
A trigger or panel loses its generated ID or ARIA linkScreen readers cannot relate the control to the content it opensPreserve the trigger/content ID contract when supplying custom markup
A tooltip is used for content that needs touch interactionTouch users cannot reliably discover the content because touch pointers do not open tooltipsUse a popover for interactive or touch-required content
A tooltip provider replaces its parent defaults instead of merging themScoped styling or timing settings disappear in nested application layersBuild defaults from the nearest parent options, then apply local overrides
A tooltip offset or flipped position is applied to the wrong axis or stale sideThe label or arrow can appear detached from its trigger after placement changesUse the position map, axis-specific offset, and resolved active position together
An accordion trigger is not inside a heading or lacks the required heading levelThe component rejects or warns about the accessible section structureKeep each trigger in an h1–h6 element or a heading role with aria-level
A sheet or drawer trigger changes its edge without matching the content presentationThe surface can open from one edge while the visual layer treats it as anotherKeep trigger direction, exposed content side, and edge styles on the same contract
A progress value is greater than its maximum or below zeroThe progressbar cannot represent the reported task stateValidate values against zero and the configured maximum
A loading toast is treated as a normal timed toastThe user loses the status before the related work finishes or the toast remains without a resultUse the promise flow for work-linked feedback and provide success or error data when needed
A tab key manager keeps a stale trigger order or active indexArrow, Home, or End moves focus to a removed, reordered, or unintended tabRebuild navigation from live triggers and synchronize from the focused trigger before handling keys

Key files

FileWhy to read it
libs/…/brn-overlay.service.tsShows the common overlay lifecycle, content attachment, stack order, focus entry, and dismissal flow.
libs/…/brn-overlay-ref.tsShows the close phase, dismissal rules, result delivery, and animation-aware disposal contract.
libs/…/brn-dialog.service.tsShows how the dialog specializes the overlay contract for components, templates, context, labels, and focus behavior.
libs/…/brn-dialog-id.tsShows the shared identity source for declarative and service-opened dialogs.
libs/…/brn-dialog-id.spec.tsShows the guarantee that the two dialog creation paths receive distinct IDs.
libs/…/brn-dialog.service.spec.tsShows the backdrop behavior for one dialog and for stacked dialogs.
libs/…/brn-dialog-ref.tsShows dialog phase changes, animation-aware closing, reopen behavior, and description tracking.
libs/…/brn-dialog-content.tsShows the content contract shared by dialogs and edge surfaces.
libs/…/brn-popover-trigger.tsShows how an anchored trigger supplies the origin and exposes its expanded state.
libs/…/brn-tooltip.tsShows tooltip triggers, viewport-aware placement, resolved position state, and accessible labeling.
libs/…/brn-tooltip-position.tsShows preferred and fallback placement, axis-specific offsets, and mapping from resolved overlay placement.
libs/…/brn-tooltip-position.spec.tsShows the guarantees for placement-axis offsets, including zero and negative values.
libs/…/brn-navigation-menu-trigger.tsShows the relationship between trigger events, panel visibility, focus entry, and keyboard exit.
libs/…/brn-command.tsShows searchable list state and active-descendant keyboard selection.
libs/…/brn-tabs.tsShows active tab ownership and automatic versus manual activation.
libs/…/brn-tabs-list.tsShows live trigger focus management, orientation-aware keys, and focus synchronization.
libs/…/brn-tabs-paginated-list.tsShows overflow handling that keeps active and focused tab labels visible.
libs/…/brn-tabs-trigger.tsShows tab semantics, selection state, disabled state, and registration with the root.
libs/…/brn-tabs.spec.tsShows guarantees for dynamic tab changes, manual focus, activation, and paginated navigation.
libs/…/brn-accordion.tsShows single or multiple disclosure state and composite keyboard focus.
libs/…/brn-accordion-trigger.tsShows the trigger-to-panel relationship and required accessible heading structure.
libs/…/brn-sheet-trigger.tsShows per-trigger edge selection for a sheet.
libs/…/brn-drawer-handle.tsShows drag dismissal and the protection against turning scroll gestures into drawer closes.
libs/…/state.tsShows shared toast creation, typed feedback, ID updates, dismissal, and promise results.
libs/…/brn-toaster.tsShows notification placement, focus access, expansion, and toaster-wide behavior.
libs/…/brn-progress.tsShows determinate and indeterminate progress semantics and value validation.
libs/…/brn-tooltip.token.tsShows the scoped default contract for tooltip timing, position, and presentation hooks.