Skip to content

Coachmark

A guided-tour step that spotlights an element already on the page.

Workspace settings

Members

3 of 10 seats used

Usage this month

Resets May 1
Message credits
x
hero.tsx

Usage guidelines

  • Use Coachmark to walk users through controls that already exist on the page. Use Popover for explanatory content anchored to a trigger, and Dialog for a task that does not point at a page element.
  • The caller owns the tour. Control open, pass the current target as an element or a selector that matches one element, and advance the step in your own state. Coachmark has no Trigger: a tour starts from product logic or from a button that sets the step.
  • Pass the step data as payload and read it from the render-function child. While the next target mounts, scrolls or animates, Coachmark keeps the previous payload in place and marks the popup data-pending and aria-busy; it also keeps the last payload through the close transition. Pass payload={undefined} when closed or when the next step is not ready, instead of a fallback value or unmounting Coachmark.
  • onOpenChange reports only the close part and Escape. Clicking the dimmed page never dismisses a coachmark, so every step needs a CoachmarkClose, which also keeps focus trapped in the popup with the default modal.
  • onStepShown runs each time a step becomes visible, including when the tour returns after stepping aside for another modal. Use it for step analytics or for marking a tour as seen.
  • Name the popup with CoachmarkTitle. Put CoachmarkStepLabel inside the title so the progress is part of the dialog's name, and keep the copy in CoachmarkDescription.
  • Point initialFocus at the primary action on walkthrough steps. Leave it out on a step the user completes on the target, so the popup takes focus and its copy is read before the user tabs to the target. When focus stays on the same action across steps, Coachmark announces the new copy through a polite live region.
  • CoachmarkPositioner accepts logical sides only: top, bottom, inline-start and inline-end. The spotlight, the page blocker and the popup are fixed to the viewport, so they follow a target inside a scroll container; when the target scrolls away, the popup stays reachable so the close action remains available.
  • When another modal covers the coachmark, it steps aside and comes back once its target is reachable again.

Anatomy

tsx
tsx

CoachmarkSpotlight dims the page around the target. CoachmarkPositioner also renders the layer that blocks the rest of the page, so the page stays blocked without a spotlight.

Examples

Letting the user act on the target

With modal="allow-target", the user completes the step on the target itself. The rest of the page stays blocked for pointer, keyboard and assistive technology, and Tab moves between the popup and the target. Close the coachmark from the target's own change handler.

Customer support bot

Draft

Only workspace members can chat.

allow-target.tsx

highlightSelectors widens the spotlight to cover related elements next to the target. The extra elements stay inert while lit; descendants of the target stay interactive. This example also passes the target as a selector.

Workflow

Last run2.30 s total
  1. StartSucceeded0.01 s
  2. Knowledge retrievalSucceeded0.42 s
  3. LLMSucceeded1.87 s

Last edited 2 minutes ago

highlight-selectors.tsx

Keyboard

KeyAction
TaborShift+TabMoves focus between the popup's controls. With modal="allow-target", focus moves between popup and target.
EscapeCalls onOpenChange with the escape-key reason. The coachmark stays open until the owner closes it.

API reference

Coachmark

Groups all parts of a guided-tour overlay that spotlights page elements and tracks step payloads across transitions. Doesn't render its own HTML element.

Props
PropTypeDefaultDetails
open requiredbooleanNo default
onOpenChange((open: boolean, eventDetails: CoachmarkChangeEventDetails) => void)No default
target requiredCoachmarkTargetNo default
highlightSelectorsstring[]No default
modal'allow-target' | truetrue
payloadPayloadNo default
onStepShown((payload: Payload) => void) | (() => void)No default
children((state: { payload: Payload; }) => React.ReactNode) | React.ReactNodeNo default

Valid prop combinations:

  • payload: Payload | undefined, onStepShown?: ((payload: Payload) => void), children?: ((state: { payload: Payload; }) => React.ReactNode) | React.ReactNode
  • payload?: undefined, onStepShown?: (() => void), children?: React.ReactNode

CoachmarkActions

Accepts the props of the element it renders.

CoachmarkArrow

Displays an element positioned against the popover anchor. Renders a <div> element.

Base UI Popover.Arrow docs

Data attributes
AttributeDescription
data-open

Present when the popup is open.

data-closed

Present when the popup is closed.

data-side

Values: 'top' | 'bottom' | 'left' | 'right' | 'inline-end' | 'inline-start'

Indicates which side the popup is positioned relative to the trigger.

data-align

Values: 'start' | 'center' | 'end'

Indicates how the popup is aligned relative to specified side.

data-uncentered

Present when the popover arrow is uncentered.

CoachmarkClose

A button that closes the popover. Renders a <button> element.

Base UI Popover.Close docs

CoachmarkDescription

A paragraph with additional information about the popover. Renders a <p> element.

Base UI Popover.Description docs

CoachmarkPopup

A container for the popover contents. Renders a <div> element.

Base UI Popover.Popup docs

Data attributes
AttributeDescription
data-pending

Present while the next step waits for its target; the previous step stays in place.

data-gliding

Present while the coachmark moves from the previous target to a new one.

data-open

Present when the popup is open.

data-closed

Present when the popup is closed.

data-starting-style

Present when the popup begins animating in.

data-ending-style

Present when the popup is animating out.

data-side

Values: 'top' | 'bottom' | 'left' | 'right' | 'inline-end' | 'inline-start'

Indicates which side the popup is positioned relative to the trigger.

data-align

Values: 'start' | 'center' | 'end'

Indicates how the popup is aligned relative to specified side.

data-instant

Values: 'click' | 'dismiss' | 'focus' | 'trigger-change'

Present if animations should be instant.

CSS variables
VariableDescription
--popup-width

The width of the popup.

--popup-height

The height of the popup.

CoachmarkPortal

A portal element that moves the popup to a different part of the DOM. By default, the portal element is appended to <body>. Renders a <div> element.

Base UI Popover.Portal docs

CoachmarkPositioner

Positions the popover against the trigger. Renders a <div> element.

Base UI Popover.Positioner docs

Props
PropTypeDefaultDetails
sideOffsetnumber | OffsetFunction25
arrowPaddingnumber16
collisionPaddingPadding8
collisionAvoidanceCollisionAvoidance{ side: 'flip', align: 'shift', fallbackAxisSide: 'none' }
stickybooleantrue
side'bottom' | 'inline-end' | 'inline-start' | 'top''bottom'
Base UI Popover.Positioner docs
Data attributes
AttributeDescription
data-pending

Present while the next step waits for its target; the previous step stays in place.

data-gliding

Present while the coachmark moves from the previous target to a new one.

data-open

Present when the popup is open.

data-closed

Present when the popup is closed.

data-anchor-hidden

Present when the anchor is hidden.

data-side

Values: 'top' | 'bottom' | 'left' | 'right' | 'inline-end' | 'inline-start'

Indicates which side the popup is positioned relative to the trigger.

data-align

Values: 'start' | 'center' | 'end'

Indicates how the popup is aligned relative to specified side.

CSS variables
VariableDescription
--available-width

Values: number

The available width between the trigger and the edge of the viewport.

--available-height

Values: number

The available height between the trigger and the edge of the viewport.

--anchor-width

Values: number

The anchor's width.

--anchor-height

Values: number

The anchor's height.

--transform-origin

Values: string

The coordinates that this element is anchored to. Used for animations and transitions.

--positioner-width

Values: number

The width of the popover's positioner. It is important to set width to this value when using CSS to animate size changes.

--positioner-height

Values: number

The height of the popover's positioner. It is important to set height to this value when using CSS to animate size changes.

CoachmarkSpotlight

An overlay displayed beneath the popover. Renders a <div> element.

Base UI Popover.Backdrop docs

Data attributes
AttributeDescription
data-pending

Present while the next step waits for its target; the previous step stays in place.

data-gliding

Present while the coachmark moves from the previous target to a new one.

data-open

Present when the popup is open.

data-closed

Present when the popup is closed.

data-starting-style

Present when the popup begins animating in.

data-ending-style

Present when the popup is animating out.

CoachmarkStepLabel

Accepts the props of the element it renders.

CoachmarkTitle

A heading that labels the popover. Renders an <h2> element.

Base UI Popover.Title docs