Skip to content

TeachingPopover

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>
    );
  },
};

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(),
  },
};

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

NameTypeRequiredDefaultDescription
stepsreadonly TeachingPopoverStep[]Yes

Steps to display in the teaching popover (a readonly array is accepted).

activeStepnumberNo

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.

defaultActiveStepnumberNo0

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 open turned it off), so a tour opened again starts over; onStepChange is called with it when the step was elsewhere.

onStepChange(step: number) => voidNo

Called with the requested step index when Next, Back or a step button of TeachingPopover.CarouselNav is activated (the button of the current step requests nothing), and, while the step is uncontrolled, with the initial step when an opening moves the step back to it (see defaultActiveStep).

onDismiss() => voidNo

Called when the popover is dismissed with Close, Escape or a TeachingPopover.Trigger that closes it. Done finishes the tour instead: it calls onFinish, not this.

onFinish() => voidNo

Called when the tour is finished: Done, the button that replaces Next on the last step, or a primaryAction on the last step whose click was not prevented. The popover closes first. Close, Escape and the Trigger call only onDismiss. Fires on every activation, like onStepChange.

primaryActionTeachingPopoverActionNo

Replaces the Next (or Done) button on every step that sets no primaryAction of its own.

secondaryActionTeachingPopoverActionNo

Replaces the Back button on every step that sets no secondaryAction of its own.

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 data-layout on the popover and on its footer. TeachingPopover.CarouselFooter has its own layout instead.

appearance'neutral' | 'brand' | 'inverted'No'neutral'

The look of the surface: neutral (the page background with a border), brand (the brand fill) or inverted (a dark surface in the light theme). The text, the Close button, the step dots and the footer buttons follow it: Next (Done) turns into a neutral secondary button and Back into a transparent one in the surface's color, so both stay legible; a primaryAction or secondaryAction you give keeps the look you give it. Rendered as data-appearance on the surface. Fluent's TeachingPopover appearance (it has brand and inverted, and its popover looks like brand by default; WaveUI keeps its neutral surface by default).

trapFocusbooleanNofalse

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 inert and a press on it does not dismiss the popover. A popover that renders in place, without a target or Trigger, traps too. Without it the popover is non-modal and takes its place in the page's Tab order next to its target. Fluent's trapFocus, which is on by default there (WaveUI's default is off so a tour does not lock the page).

openbooleanNo

Controlled visibility of the teaching popover.

defaultOpenbooleanNotrue (false with a direct TeachingPopover.Trigger)

Initial visibility for uncontrolled usage: true (a tour that shows on page load), or false when a TeachingPopover.Trigger is a direct child (a Fragment is fine), which then opens it.

onOpenChange(open: boolean) => voidNo

Called with false when Close, Done or Escape dismisses the popover, and with the new state when a TeachingPopover.Trigger opens or closes it.

closeLabelstringNo'Close'

Accessible name of the built-in Close button (an icon-only button). Localize it with the page's language.

labelsTeachingPopoverLabelsNo

Text of the Back, Next and Done buttons, the wording of the step position (“step 2 of 3”) and the names of TeachingPopover.CarouselNav's step buttons, for localization. Unset members keep their English defaults.

targetReact.RefObject<HTMLElement | null> | HTMLElement | VirtualElement | nullNo

The element the popover points at (a ref, the element, or a VirtualElement: a rectangle such as a point; an inline object is fine). When given, the popover is rendered in a portal, positioned next to it with a beak, and flips or shifts to stay in view; without it (undefined) the popover renders inline where it is placed (0.4 behaviour), or, with a TeachingPopover.Trigger, points at the trigger. While the target is null or has not been positioned against yet (an element held in state that is not set yet, a ref that is not attached), the popover stays hidden: it is not shown, takes no focus, announces no step change and does not handle Escape until it can point at the target. It hides the same way when the target goes away later and shows again when a target returns.

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 (target={step === 0 ? aRef : bRef}) without hiding, and a switch to a ref that is not attached hides the popover right after that commit. Pass the element held in state when the target can mount or unmount without the popover re-rendering.

side'top' | 'bottom' | 'start' | 'end' | 'left' | 'right'No'bottom'

Side of the target to open on; start/end follow the writing direction.

align'start' | 'center' | 'end'No'center'

Alignment along the target's edge.

positioningPopupPositioningNo`{ offset: 12 }`

Advanced positioning (Fluent's positioning): offset, fitViewport, matchReferenceWidth, fallbackPlacements and target (used when the target prop is not set). side and align stay separate props.

motionMotionSlot | nullNothe fade and slide above

The motion of the surface TeachingPopover renders (next to a TeachingPopover.Surface it is ignored, with a development warning: give it to the Surface). By default the surface fades in over 200 ms with a decelerating curve and out over 100 ms with an accelerating curve, and, pointed at a target (or the Trigger), also slides 4px away from it on the side it opened on, and back as it closes; under reduced motion it appears and disappears at once. null turns the motion off (the surface still renders its data-presence phases, which then end at once); a class string or { className } replaces the default classes with yours (see MotionSlot), also under a WaveProvider with motion="none", which otherwise turns the default off. Fluent's TeachingPopover surfaceMotion (a TeachingPopover is a Popover there).

childrenReact.ReactNodeNo

TeachingPopover.Trigger and TeachingPopover.Surface (Fluent's composition), rendered where they are written. Without a TeachingPopover.Surface among them, the popover renders its surface itself, after the children, with the element props given here (className, style, ref, motion, …); with one (best written directly inside, a Fragment is fine: see TeachingPopover.Surface), the Surface takes them instead.

refReact.Ref<HTMLDivElement>No

Ref to the popover surface (role="dialog"). Ignored next to a TeachingPopover.Surface (pass it to the 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 preventDefault() in yours skips the popover's handling of the event, its own handlers of the part included), your ref beside its ref. Every attribute the popover sets on a part is locked and keeps its value; you add the attributes it does not set. A part takes no children. The parts reach what the popover draws itself, in the steps form and in the parts form alike: the beak of the surface (its own, or a TeachingPopover.Surface), the Close button of TeachingPopover.Header, and the step dots and the Back and Next buttons of TeachingPopover.Footer and TeachingPopover.CarouselFooter. The buttons that replace Back and Next are secondaryAction and primaryAction, and TeachingPopover.CarouselNav takes its own slotProps. Kept next to a TeachingPopover.Surface too (the parts read it from the popover's context), so keep the object's identity across renders (a constant, or useMemo): a new object each render re-renders every part that reads it. Fluent UI's TeachingPopover parts take their own props instead.

Any other prop is passed to the element it renders (HTMLDivElement).

Parts

  • beak
  • closeButton
  • dot
  • backButton
  • nextButton
  • TeachingPopover.Trigger
  • TeachingPopover.Surface
  • TeachingPopover.Header
  • TeachingPopover.Title
  • TeachingPopover.Body
  • TeachingPopover.Footer
  • TeachingPopover.Carousel
  • TeachingPopover.CarouselNav
  • TeachingPopover.CarouselPageCount
  • TeachingPopover.CarouselFooter

Stable class names

PartClass
rootwave-teaching-popover
beakwave-teaching-popover__beak
closeButtonwave-teaching-popover__close-button
titlewave-teaching-popover__title
bodywave-teaching-popover__body
footerwave-teaching-popover__footer
dotwave-teaching-popover__dot
backButtonwave-teaching-popover__back-button
nextButtonwave-teaching-popover__next-button
primaryButtonwave-teaching-popover__primary-button
secondaryButtonwave-teaching-popover__secondary-button