Raft 设计系统

组件 · 浮层

CoachMark

One stop of a tour — a 300px popover with an arrow, anchored to the thing it explains, which holds the Located wash while the stop is open.

实验性也叫 Tour, Coach marks, Product tour
import { CoachMark } from "@botiverse/raft-ui/wip";
本页尚未翻译
译文完成之前,这里显示英文原文。 阅读英文版

A coach mark is one stop of a tour of a screen the person has just entered: a bubble that points at one thing, says what it is in a sentence, and moves on with Next. When to run a tour, how many stops, what they say and where focus goes after it are in Coach marks; this page is the part that draws a stop. Experimental, from @botiverse/raft-ui/wip.

coach-mark/coach-mark-tour

When to use

SituationUse
A tour of a screen the person enters for the first timeCoachMark, one per stop
One sentence about a control, on hoverTooltip
A little choice or input the person openedPopover
An error, a confirmation or anything the person must answerFeedback

Anatomy

  • CoachMark: the root of one stop. anchor is its target, an element or a ref (read after every render, so a ref that moves to another element moves the stop); open (default true) shows it; onDismiss is called when the person ends the tour from the bubble: Esc in it, or a PopoverClose in it. Required.
  • CoachMarkContent: the bubble, 300px, 8px from the target and at least 8px from the window's edge, with an arrow on whichever side it opens (side, default bottom; align, default center). Required.
  • PopoverBody with PopoverTitle and PopoverDescription: the thing's name and one sentence about it.
  • CoachMarkAction: optional, one more thing the stop offers, an outline button on its own row under the text (Turn on notifications).
  • CoachMarkActions: the last row. CoachMarkCount ("2 of 6") at its start, then Skip (a ghost Button) and CoachMarkNext.
  • CoachMarkNext: Next, or Done on the last stop, the pink button.

The product owns the tour: which stop is open, its words, and what Skip, Next and Done do. Render one CoachMark for the open stop and change its anchor and text for the next one.

Behavior

  • The target holds the Located wash at full strength while its stop is open, and loses it when the stop closes or moves on: CoachMark sets data-located="held" on it and puts back what was there (Located). A target that is already selected keeps its selection. For a list row, anchor the whole row, so the wash takes the row's inset shape (fill-cell-selected).
  • It is non-modal. No scrim, and a press outside and focus leaving the bubble don't close it: the person may be answering the agent under it.
  • In the Tab order the bubble comes right after its target: Tab from the target (or its last control, or the last control before it when the target takes no focus) goes to the bubble's first button, Tab from its last button goes on to what follows the target, and Shift+Tab goes back the same way. The bubble has no trigger for Base UI to return to, so CoachMark places it.
  • When a stop opens, and when it moves to the next target (another anchor), focus goes to CoachMarkNext, unless the person is typing in a field: then it stays there. When the same anchor, a ref, comes to point at a new element (a row given a new key), the stop stays where it is and focus moves to CoachMarkNext only if it was already in the bubble. Pass a different ref (or element) for each stop, never the same ref moved to the next target.
  • Esc while focus is in the bubble calls onDismiss: the person ended the tour. Esc elsewhere, in the composer for instance, goes on to what has focus (closing its suggestions, cancelling an edit) and leaves the tour open.
  • Closing moves no focus: the product puts it in the composer when the tour ends, by Skip, Done or Esc.

Accessibility

  • The bubble has the dialog role and is named by its PopoverTitle.
  • Focus moves only as above, never out of a field the person is typing in.
  • The Located wash is only a look; the bubble's title names the thing for a screen reader.

Rules

  • Make the bubble 300px wide; CoachMarkContent does.
  • Write a title and one sentence. A stop that needs two sentences is two stops.
  • Count the stops on every bubble; leave Skip off the last one, which has Done.
  • Point each stop at one thing, and anchor it to something every platform has.
  • The other rules of a tour are in Coach marks.

API

CoachMark

实验性One stop of a tour: a non-modal popover anchored to its target, which holds the Located wash while the stop is open (design/patterns/coach-marks.md). The product owns the tour: which stop is open, the copy, and where focus goes when it ends.
Prop类型默认值
anchor (required)What this stop is about, an element or a ref to one. While the stop is open its target holds the Located wash (`data-located="held"`); pass the whole row for a list row. A ref is read after every render, so a ref that moves to another element (a row given a new key) moves the wash too.Element | RefObject<Element | null>
childrenReactNode
onDismissCalled when the person ends the tour from the bubble: Esc while focus is in it, or a `PopoverClose` in it. Skip and Done are the product's own buttons and call its own handlers. A press outside and focus leaving never close it, and Esc pressed anywhere else goes on to what has focus.() => void
openWhether the stop is showing.booleantrue

CoachMarkAction, CoachMarkActions

实验性One more thing the stop offers (Turn on notifications), an `outline` button on its own row under the text.

接受其元素的全部属性。

CoachMarkContent

实验性The bubble: 300px, 8px from its target and at least 8px from the window's edge (or frame inset), with an arrow on whichever side it opens.
Prop类型默认值
collisionPaddingAdditional space to maintain from the edge of the collision boundary: 8px from the window's edge, and 8px from a frame inset where a shell keeps one. A value you pass is kept as it is.Padding8
containerHTMLElement | ShadowRoot | RefObject<HTMLElement | ShadowRoot | null>
portalPropsPopoverPortalProps
alignHow to align the popup relative to the specified side.Align"center"
alignOffsetAdditional offset along the alignment axis in pixels. Also accepts a function that returns the offset to read the dimensions of the anchor and positioner elements, along with its side and alignment.number | OffsetFunction0
arrowPaddingMinimum distance to maintain between the arrow and the edges of the popup.number5
collisionAvoidanceDetermines how to handle collisions when positioning the popup.CollisionAvoidance
collisionBoundaryAn element or a rectangle that delimits the area that the popup is confined to.Boundary'clipping-ancestors'
disableAnchorTrackingWhether to disable the popup from tracking any layout shift of its positioning anchor.booleanfalse
positionMethodDetermines which CSS `position` property to use."fixed" | "absolute"'absolute'
renderAllows you to replace the component's HTML element with a different tag, or compose it with another component.ReactElement | ((props, state) => ReactElement)
sideWhich side of the anchor element to align the popup against. May automatically change to avoid collisions.Side"bottom"
sideOffsetDistance between the anchor and the popup in pixels. Also accepts a function that returns the distance to read the dimensions of the anchor and positioner elements, along with its side and alignment.number | OffsetFunction8
stickyWhether to maintain the popup in the viewport after the anchor element was scrolled out of view.booleanfalse

Also takes the attributes of its element.

CoachMarkCount

实验性Which stop this is, "2 of 6", in Space Mono.

接受其元素的全部属性。

CoachMarkNext

实验性Next, or Done on the last stop: the pink button, and where focus goes when the stop opens.
Prop类型默认值
loadingBusy: shows the spinner and blocks activation (click, Enter, Space and form submission) while keeping the button focusable. A busy button is `aria-disabled`, not natively `disabled`, so the focus a press left on it stays there and is still there when the wait ends.boolean
loadingLabelThe spinner's accessible name while `loading`: say what is happening.string
size`md` (32px) and `icon-md` for rows, cards, banners, toolbars and panel headers; `lg` and `icon-lg` (the control height) for dialog footers, forms and beside a field; `xl` for a full-width call to action; `icon-sm` (28px, a 44px hit area) for an icon-only action on a line of a row or a card, such as a comment header's More, never in a toolbar. The size follows the place: see Button › Size by place."md" | "lg" | "xl" | "icon-sm" | "icon-md" | "icon-lg" | DeprecatedButtonSize
focusableWhenDisabledWhether the button should be focusable when disabled.booleanfalse
nativeButtonWhether the component renders a native `<button>` element when replacing it via the `render` prop. Set to `false` if the rendered element is not a button (for example, `<div>`).booleantrue
renderAllows you to replace the component's HTML element with a different tag, or compose it with another component.ReactElement | ((props, state) => ReactElement)

Also takes the attributes of its element.

改动

  • 0.102.0 · AddedCoachMark, one stop of a tour (work in progress, from @botiverse/raft-ui/wip; [CoachMark](https://raft-design.botiverse.build/components/coach-mark/), [Coach marks](https://raft-design.botiverse.build/patterns/coach-marks/)). CoachMark takes the stop's anchor, open and onDismiss; CoachMarkContent is the 300px bubble with an arrow, 8px from its target; CoachMarkAction, CoachMarkActions, CoachMarkCount and CoachMarkNext (the pink Next or Done) lay out its rows, with PopoverBody, PopoverTitle and PopoverDescription for the text. While a stop is open its target holds the Located wash (data-located="held"). The bubble is non-modal: a press outside and focus leaving don't close it, focus goes to Next when a stop opens unless the person is typing in a field, its buttons come right after its target in the Tab order, and Esc in the bubble (or a PopoverClose) calls onDismiss, while Esc anywhere else goes on to what has focus.