Spinner
A busy indicator that says what it is waiting for.
Examples
Playground
Size
`text` is 1em: it takes the size of the text around it, so it matches a line at any type size, which is what Button uses. `sm` (16px) and `md` (24px) are fixed, for a spinner that stands on its own, such as a loading panel.
Install
npx shadcn add @hipuku/spinnerUsage
import { Spinner } from '@/components/haus/components/Spinner'
<Spinner label="Loading results" />API
Spinner also takes its element's own attributes and forwards its ref.
| Prop | Type | Description |
|---|---|---|
size | "text" | "sm" | "md" | |
label | string | What a screen reader announces while this is on screen. Defaulted rather than required, because the failure this component exists to stop is a spinner that announces nothing, and a required prop is one a caller can satisfy with an empty string. |
announcedBy | string | Say that something else already announces the wait, and name it.
Typed as the text that speaks instead of as a boolean, deliberately. Every
product that got this wrong got it wrong by silencing the spinner and
putting nothing in its place: drift renders aria-hidden="true" at both
its call sites, so a reader waiting on a crawl is told nothing is
happening. A boolean would make that the easy thing to write again.
The legitimate case is real and vault has it: <Spinner /> Extracting...
announces twice, once for the spinner and once for the text. Passing the
text here silences the spinner and records what covers it. |
Sizes
text matches the text it sits beside, for a spinner inside a label or a button. sm and md are
for a spinner that stands on its own, such as a loading panel.
Announcing the wait
By default a Spinner is a status region labelled with label, so a screen reader can tell that
something is happening. If something else already announces the wait, pass that text as
announcedBy and the spinner stays silent, so the wait is not announced twice.
An announcement is not guaranteed, because a region that appears already holding its text is not
reliably read. For a wait that must be heard, keep a live region on the page and put the text in it
when loading starts, then pass that text as announcedBy.
Accessibility
- Not interactive.
- With reduced motion it keeps turning, slower, because a still ring reads as broken.