Skip to content

Spinner

Spinner

An indeterminate loading indicator.

- The root is a role="status" live region (override role, e.g. role="none" inside a region that already announces the busy state, or role="progressbar", which label names unless you pass aria-label or aria-labelledby).
- The region mounts **empty** and receives its label (default "Loading") one animation frame after the spinner is shown, so screen readers announce it (a live region that mounts with its content is often not announced). With labelVisible the label also shows next to the ring from that frame on.
- delay holds back the ring and the label for that many milliseconds (the region mounts at once), so a fast load does not flash the spinner. The root's data-state is delayed, then shown.
- labelPosition places the visible label before, after, above or below the ring, and the root carries it as data-label-position. label takes any content, not only text.
- size falls back to the size of a surrounding SpinnerContextProvider (a parent that sizes the spinners it holds), then medium.
- appearance="inverted" draws the spinner in the current text color, for a primary Button or another brand or inverted surface. The root carries data-appearance.
- The ring is decorative (aria-hidden) and spins slower for reduced motion. In forced-colors mode its arc is drawn in Highlight on a Canvas track, so the rotation stays perceivable.

Examples

Default

export const Default: Story = {};

Sizes

export const Sizes: Story = {
  render: ({ size: _size, label: _label, ...args }) => (
    <div className="flex items-center gap-4">
      {sizes.map(([size, label]) => (
        <Spinner key={size} size={size} label={label} {...args} />
      ))}
    </div>
  ),
};

With Label

export const WithLabel: Story = {
  args: {
    size: 'medium',
    label: 'Loading content...',
    labelVisible: true,
  },
};

Inverted

export const Inverted: Story = {
  args: {
    appearance: 'inverted',
    label: 'Saving',
  },
  render: ({ size: _size, labelVisible: _labelVisible, ...args }) => (
    <div className="flex flex-wrap items-center gap-4">
      <Button appearance="primary" icon={<Spinner {...args} size="extra-small" />}>
        Saving
      </Button>
      <div className="inline-flex items-center rounded bg-wave-inverted px-3 py-2 text-wave-inverted-foreground">
        <Spinner {...args} size="small" labelVisible />
      </div>
    </div>
  ),
};

Delayed

export const Delayed: Story = {
  args: {
    delay: 800,
    label: 'Loading results',
    labelVisible: true,
  },
  render: (args) => <DelayedDemo {...args} />,
};

Label Positions

export const LabelPositions: Story = {
  args: { labelVisible: true, label: 'Loading' },
  render: ({ labelPosition: _position, ...args }) => (
    <div className="flex flex-wrap items-center gap-8">
      {labelPositions.map((position) => (
        <Spinner key={position} labelPosition={position} {...args} label={position} />
      ))}
    </div>
  ),
};

Size Scale

export const SizeScale: Story = {
  render: ({ size: _size, label: _label, ...args }) => (
    <div className="flex items-center gap-4">
      {spinnerSizes.map((size) => (
        <Spinner key={size} size={size} label={size} {...args} />
      ))}
    </div>
  ),
};

Size From Context

export const SizeFromContext: Story = {
  render: () => (
    <SpinnerContextProvider size="huge">
      <div className="flex items-center gap-4">
        <Spinner label="Provider size" />
        <Spinner size="tiny" label="Own size" />
        <Spinner
          labelVisible
          label={
            <>
              Loading <strong>results</strong>
            </>
          }
        />
      </div>
    </SpinnerContextProvider>
  ),
};

Props

NameTypeRequiredDefaultDescription
size'extra-small' | 'small' | 'medium' | 'large' | 'extra-large' | 'extra-tiny' | 'tiny' | 'huge'No'medium', or the size of the surrounding `SpinnerContextProvider`

Size of the spinner: extra-tiny (16px), tiny (20px), extra-small (12px), small (16px), medium (24px), large (36px), huge (44px) or extra-large (48px). The five sizes of 0.x keep their pixel sizes, so medium is 24px where Fluent's is 32px; extra-tiny, tiny and huge are Fluent's names with Fluent's pixel sizes. Without one, a surrounding SpinnerContextProvider gives the size (Fluent's SpinnerContext).

labelReact.ReactNodeNo'Loading'

What the spinner's status region announces (and what shows with labelVisible): a string, or any content (Fluent's label slot, which takes a ReactNode). Localize it. With role="progressbar" only a string names the spinner (aria-label): pass an aria-label or aria-labelledby of your own with other content.

labelVisiblebooleanNo

Whether the label text is visually displayed alongside the spinner.

labelPosition'before' | 'after' | 'above' | 'below'No'after'

Where the visible label sits relative to the ring: after (the ring first, in the reading direction), before, below or above. The DOM order is the same in each; only the layout changes, so the status region announces the label alike. The root carries it as data-label-position. Fluent's labelPosition.

appearance'primary' | 'inverted'No'primary'

primary: a primary arc on the track color. inverted: drawn in the current text color (a 30% track), for brand or inverted surfaces such as a primary Button.

delaynumberNo0

Milliseconds to wait before the ring and the label appear, so a fast load does not flash the spinner. The status region is mounted (empty) at once and announces the label once shown. A non-finite or negative value means 0.

roleReact.AriaRoleNo'status'

Role of the root; a forwarded undefined keeps the default live region. Use none inside a region that already announces the busy state, or progressbar, which label names (aria-label) unless you pass aria-label or aria-labelledby (a progress bar is not named by its content).

refReact.Ref<HTMLSpanElement>No
slotProps{ spinner?: SlotPart<'span'>; label?: SlotPart<'span'> }No

Props for the elements the spinner draws inside its root, by part, merged into each part's own (Fluent UI's spinner and label slot props): your classes after the part's (yours win a conflict), your styles over its styles, your attributes and handlers added, your ids added to its aria-labelledby and aria-describedby, and your ref beside its ref. Every attribute the spinner sets on a part is locked and keeps its value; you add the attributes it does not set. A part takes no children. The root, the status region (or the role you give it), takes the component's own props. Neither part carries a handler of the spinner.

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

Parts

  • spinner
  • label

Stable class names

PartClass
rootwave-spinner
spinnerwave-spinner__spinner
labelwave-spinner__label