TeachingPopover
A step-by-step onboarding popover (a non-modal role="dialog") with Back/Next (Done on the last step) and Close.
- Visibility is controllable: open/defaultOpen (default true, or false with a direct TeachingPopover.Trigger)/onOpenChange; Close, Escape (anywhere in the document) and the Trigger dismiss it and call onDismiss; Done closes it and calls onFinish.
- The step is controllable with activeStep/defaultActiveStep/onStepChange and clamped to the available steps. An uncontrolled step starts again at defaultActiveStep each time the popover opens, so a tour finished with Done or closed midway starts over (onStepChange reports the move back); a controlled activeStep is left as it is. The heading carries a visually hidden “step n of m”, the new step is announced politely, and Back stays focusable (aria-disabled) on the first step.
- primaryAction and secondaryAction (on the popover, or on a step, which wins) replace Next/Done and Back: a label, a Button-like element or a slot object. The consumer's onClick runs first, then the step's normal action unless it called preventDefault(). Done calls onFinish; footerLayout stacks the buttons.
- The built-in text is English: labels localizes Back, Next, Done and the step position, and closeLabel the Close button.
- Focus moves to the popover when it opens and returns to the element that had it when it closes (with target, to the target when nothing had focus, e.g. a tour opened on page load).
- With target, the popover is portaled and positioned next to that element with a beak (it inherits the surface colors); it stays hidden while the target is null, not positioned yet or no longer mounted (a ref target is read after each render of the popover; see target).
- With a VirtualElement target there is no element to follow: the popover keeps the place of its portal in the keyboard order.
- With an element or ref target, the keyboard order treats the popover as if it followed the target: Tab past its last button continues after the target, Shift+Tab from its first button (or from the popover itself) returns to the target (for a target outside the Tab order, to the last control inside it, else to the control before it), Tab from there enters the popover, and Shift+Tab from the control after the target enters it at its last button. Tab from the last control of the page moves past the popover (it was visited after the target), and Shift+Tab from outside the page reaches the page's last control first, so a lap visits it once and Tab never cycles. With no control at or before the target, the popover is reached where it is portaled, at the end of the page: Tab from the page's last control and Shift+Tab from outside the page enter it.
- **Motion.** The surface fades in over 200 ms and out over 100 ms as it closes; pointed at a target (or the Trigger) it also slides 4px away from it on the side it is placed on (data-side, after a flip: it enters once it has its position), and back. Under reduced motion it appears and disappears at once. motion (on TeachingPopover for the surface it renders, or on TeachingPopover.Surface) turns it off (null) or replaces its classes, and a WaveProvider with motion="none" turns the default off. The surface mounts through the presence core: it carries data-presence and data-state="open", and while it closes data-state="closed" and inert, so it stays on screen, where it was and on the step it closed on, until its exit ends. Escape, focus and the Trigger's aria-expanded follow the open state, not the exit: focus inside a closing popover moves, in the commit that closes it, to where it returns focus. A popover open by default animates in when it mounts in the browser, and one opened again during its exit enters again on the same surface (on its first step, as every opening). Without motion it unmounts as soon as it closes.
- **Parts** (Fluent's composition): TeachingPopover.Trigger opens and closes the popover, gets focus back when it closes and, without a target, is what it points at; written directly inside TeachingPopover (a Fragment is fine), it makes the popover start closed (defaultOpen false). TeachingPopover.Surface is the surface itself: it takes the className, style, ref and other element props that the steps form takes on TeachingPopover. Inside it, TeachingPopover.Header (the Close button, with an optional caption and icon), TeachingPopover.Title (the step title with the hidden step position; it names the popover), TeachingPopover.Body (the step body, after an optional media) and TeachingPopover.Footer (the step dots and the buttons) each show their share of the current step unless given children; a Surface without children shows all four, which is what the steps form renders. Both forms share one state: the steps, the labels, the actions and the callbacks stay on TeachingPopover. A part outside a TeachingPopover throws in development.
- **Carousel parts**: TeachingPopover.Carousel holds the current step's page (the title and body) and TeachingPopover.CarouselFooter, the bottom row with the step buttons: initialStepText turns the first step's Back into a button that dismisses the popover (“Not now”), finalStepText relabels Done, and layout ('offset' or 'centered') places the indicator. The indicator is the decorative step dots unless you place TeachingPopover.CarouselNav (interactive step buttons, named by labels.navButton, each a Tab stop, the current one with aria-current="step") or TeachingPopover.CarouselPageCount (a visible “2 of 3”, worded by a render function) there. steps stays the only source of the pages, so there is no card part.
The parts are also exported under flat names (TeachingPopoverTrigger, TeachingPopoverSurface, TeachingPopoverHeader, TeachingPopoverTitle, TeachingPopoverBody, TeachingPopoverFooter, TeachingPopoverCarousel, TeachingPopoverCarouselNav, TeachingPopoverCarouselPageCount, TeachingPopoverCarouselFooter) for React Server Components, which cannot use the dotted form; dotted access (TeachingPopover.Trigger) needs a client file.
Examples
Default
This example opens a dialog or panel. Use the button to show it.
export const Default: Story = {};Second Step
This example opens a dialog or panel. Use the button to show it.
export const SecondStep: Story = {
args: {
defaultActiveStep: 1,
},
};Last Step
This example opens a dialog or panel. Use the button to show it.
export const LastStep: Story = {
args: {
defaultActiveStep: 3,
},
render: ({ onOpenChange, ...args }) => {
const [open, setOpen] = React.useState(true);
if (!open) {
return <Button onClick={() => setOpen(true)}>Show the tip again</Button>;
}
return (
<TeachingPopover
open={open}
onOpenChange={(next) => {
setOpen(next);
onOpenChange?.(next);
}}
{...args}
/>
);
},
};Single Step
This example opens a dialog or panel. Use the button to show it.
export const SingleStep: Story = {
args: {
steps: [{ title: 'Quick Tip', body: 'Press Ctrl+K to open the command palette.' }],
},
};Anchored To Target
This example opens a dialog or panel. Use the button to show it.
export const AnchoredToTarget: Story = {
args: {
side: 'bottom',
align: 'start',
},
render: (args) => {
const targetRef = React.useRef<HTMLButtonElement>(null);
return (
<div style={{ paddingBottom: 240 }}>
<Button ref={targetRef} appearance="primary">
New Project
</Button>
<TeachingPopover target={targetRef} {...args} />
</div>
);
},
};Multi Target Tour
This example opens a dialog or panel. Use the button to show it.
export const MultiTargetTour: Story = {
args: {
steps: [
{ title: 'Create a Project', body: 'Start a new project from here.' },
{ title: 'Invite Your Team', body: 'Share the project with your collaborators.' },
{ title: 'Adjust Settings', body: 'Change notifications and permissions at any time.' },
],
side: 'bottom',
align: 'start',
},
render: ({ onStepChange, ...args }) => {
const projectRef = React.useRef<HTMLButtonElement>(null);
const shareRef = React.useRef<HTMLButtonElement>(null);
const settingsRef = React.useRef<HTMLButtonElement>(null);
const [step, setStep] = React.useState(0);
const target = step === 0 ? projectRef : step === 1 ? shareRef : settingsRef;
return (
<div style={{ paddingBottom: 240 }}>
<div className="flex gap-2">
<Button ref={projectRef} appearance="primary">
New Project
</Button>
<Button ref={shareRef}>Share</Button>
<Button ref={settingsRef}>Settings</Button>
</div>
<TeachingPopover
activeStep={step}
onStepChange={(next) => {
setStep(next);
onStepChange?.(next);
}}
target={target}
{...args}
/>
</div>
);
},
};Footer Actions
This example opens a dialog or panel. Use the button to show it.
export const FooterActions: Story = {
args: {
steps: [
{
title: 'Welcome to the App',
body: 'This quick tour will help you get started with the key features.',
secondaryAction: { as: 'a', href: '#docs', children: 'Read the docs' },
},
sampleSteps[1],
{
title: "You're All Set!",
body: 'You now know the basics. Explore the app to discover more features.',
primaryAction: 'Finish setup',
},
],
primaryAction: 'Continue',
onFinish: fn(),
},
};Vertical Footer
This example opens a dialog or panel. Use the button to show it.
export const VerticalFooter: Story = {
args: {
footerLayout: 'vertical',
onFinish: fn(),
},
};Tour From Parts
This example opens a dialog or panel. Use the button to show it.
export const TourFromParts: Story = {
args: {
onFinish: fn(),
},
render: (args) => (
<div style={{ paddingBottom: 320 }}>
<TeachingPopover {...args} defaultOpen>
<TeachingPopover.Trigger>
<Button appearance="primary">Take the tour</Button>
</TeachingPopover.Trigger>
{tourParts}
</TeachingPopover>
</div>
),
};Motion
export const Motion: Story = {
render: (args) => (
<div className="flex flex-wrap gap-4" style={{ paddingBottom: 240 }}>
{motionCases(fadeAndZoom).map(({ label, motion }) => (
// The story renders one popover per case; every other arg is forwarded.
<TeachingPopover key={label} {...args} motion={motion}>
<TeachingPopover.Trigger>
<Button>{label}</Button>
</TeachingPopover.Trigger>
</TeachingPopover>
))}
</div>
),
};Page Count Header And Media
This example opens a dialog or panel. Use the button to show it.
export const PageCountHeaderAndMedia: Story = {
args: {
onFinish: fn(),
},
render: (args) => (
<div style={{ paddingBottom: 360 }}>
<TeachingPopover {...args} defaultOpen>
<TeachingPopover.Trigger>
<Button appearance="primary">Take the tour</Button>
</TeachingPopover.Trigger>
<TeachingPopover.Surface>
<TeachingPopover.Header icon={<BulbGlyph />}>Tip</TeachingPopover.Header>
<TeachingPopover.Carousel>
<TeachingPopover.Title />
<TeachingPopover.Body
media={<span className="block h-16 w-full rounded-md bg-wave-card" />}
/>
<TeachingPopover.CarouselFooter>
<TeachingPopover.CarouselNav />
<TeachingPopover.CarouselPageCount>
{(current, total) => `Step ${current} of ${total}`}
</TeachingPopover.CarouselPageCount>
</TeachingPopover.CarouselFooter>
</TeachingPopover.Carousel>
</TeachingPopover.Surface>
</TeachingPopover>
</div>
),
};Appearances
This example opens a dialog or panel. Use the button to show it.
export const Appearances: Story = {
render: ({ ...args }) => (
<div className="flex flex-wrap gap-4" style={{ paddingBottom: 40 }}>
{(['neutral', 'brand', 'inverted'] as const).map((appearance) => (
<TeachingPopover
key={appearance}
{...args}
appearance={appearance}
steps={[
{ title: `A ${appearance} tip`, body: 'Press Ctrl+K to open the command palette.' },
{ title: 'Another tip', body: 'Drag a card to reorder it.' },
]}
defaultOpen
/>
))}
</div>
),
};Trap Focus
export const TrapFocus: Story = {
args: { trapFocus: true },
render: (args) => (
<div style={{ paddingBottom: 360 }}>
<TeachingPopover {...args}>
<TeachingPopover.Trigger>
<Button appearance="primary">Take the tour</Button>
</TeachingPopover.Trigger>
</TeachingPopover>
</div>
),
};Props
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
steps | readonly TeachingPopoverStep[] | Yes | Steps to display in the teaching popover (a readonly array is accepted). | |
activeStep | number | No | Controlled index of the displayed step. Out-of-range values are clamped to the first or last step (with a development warning). Opening the popover leaves it as it is. | |
defaultActiveStep | number | No | 0 | Initial step index for uncontrolled usage, and the step the popover starts on again each time it opens (after Done, Close, Escape or the Trigger closed it, or a controlled |
onStepChange | (step: number) => void | No | Called with the requested step index when Next, Back or a step button of | |
onDismiss | () => void | No | Called when the popover is dismissed with Close, Escape or a | |
onFinish | () => void | No | Called when the tour is finished: Done, the button that replaces Next on the last step, or a | |
primaryAction | TeachingPopoverAction | No | Replaces the Next (or Done) button on every step that sets no | |
secondaryAction | TeachingPopoverAction | No | Replaces the Back button on every step that sets no | |
footerLayout | 'horizontal' | 'vertical' | No | 'horizontal' | How the footer lays out the step dots and the buttons: side by side, or the dots above buttons that fill the width. Rendered as |
appearance | 'neutral' | 'brand' | 'inverted' | No | 'neutral' | The look of the surface: |
trapFocus | boolean | No | false | Traps focus in the popover while it is shown: Tab and Shift+Tab cycle between the Close button, the step buttons and anything else in the surface, toasts and popups opened from it included, and cannot reach the page behind it. Focus still moves to the surface when it shows, and Escape and the Close button still dismiss it; the page is not made |
open | boolean | No | Controlled visibility of the teaching popover. | |
defaultOpen | boolean | No | true (false with a direct TeachingPopover.Trigger) | Initial visibility for uncontrolled usage: |
onOpenChange | (open: boolean) => void | No | Called with | |
closeLabel | string | No | 'Close' | Accessible name of the built-in Close button (an icon-only button). Localize it with the page's language. |
labels | TeachingPopoverLabels | No | Text of the Back, Next and Done buttons, the wording of the step position (“step 2 of 3”) and the names of | |
target | React.RefObject<HTMLElement | null> | HTMLElement | VirtualElement | null | No | The element the popover points at (a ref, the element, or a An element (for example one held in state through a callback ref) is followed as soon as the prop changes. A ref cannot be observed, so it is read after each render of the popover is committed, wherever the target is in the tree: an element attaching to or detaching from the ref is noticed the next time the popover renders (for example when the parent that mounts or unmounts the target re-renders it), not in a commit that does not render the popover. A memoized popover whose target mounts or unmounts in another subtree therefore stays hidden, or keeps pointing at the removed element, until it renders again. A newly passed ref keeps the previous visibility until it has been read, so a tour can move between attached refs ( | |
side | 'top' | 'bottom' | 'start' | 'end' | 'left' | 'right' | No | 'bottom' | Side of the |
align | 'start' | 'center' | 'end' | No | 'center' | Alignment along the |
positioning | PopupPositioning | No | `{ offset: 12 }` | Advanced positioning (Fluent's |
motion | MotionSlot | null | No | the fade and slide above | The motion of the surface TeachingPopover renders (next to a |
children | React.ReactNode | No |
| |
ref | React.Ref<HTMLDivElement> | No | Ref to the popover surface ( | |
slotProps | { beak?: SlotPart<'div'>; closeButton?: SlotPart<'button'>; dot?: SlotPart<'span'>; backButton?: SlotPart<'button'>; nextButton?: SlotPart<'button'> } | No | Props for the elements the popover draws besides your content, by part, merged into each part's own: your classes after the part's (yours win a conflict), your styles over its styles, your attributes and handlers added (yours run first, and |
Any other prop is passed to the element it renders (HTMLDivElement).
Parts
beakcloseButtondotbackButtonnextButtonTeachingPopover.TriggerTeachingPopover.SurfaceTeachingPopover.HeaderTeachingPopover.TitleTeachingPopover.BodyTeachingPopover.FooterTeachingPopover.CarouselTeachingPopover.CarouselNavTeachingPopover.CarouselPageCountTeachingPopover.CarouselFooter
Stable class names
| Part | Class |
|---|---|
root | wave-teaching-popover |
beak | wave-teaching-popover__beak |
closeButton | wave-teaching-popover__close-button |
title | wave-teaching-popover__title |
body | wave-teaching-popover__body |
footer | wave-teaching-popover__footer |
dot | wave-teaching-popover__dot |
backButton | wave-teaching-popover__back-button |
nextButton | wave-teaching-popover__next-button |
primaryButton | wave-teaching-popover__primary-button |
secondaryButton | wave-teaching-popover__secondary-button |