Progress
Shows how far a task that takes a while has got, such as an upload. It renders a div with role="progressbar" and the value in aria-valuenow, aria-valuetext and the CSS custom property --progress, and draws nothing: size the indicator with --progress. A value of null is indeterminate, for a task whose progress is unknown. The role requires a name: give it aria-label, or aria-labelledby naming an element. When it shows a region loading, set aria-busy="true" on that region until it has loaded, and point the region's aria-describedby at the progress bar.
- Size
- 1.2 kB
Example
import { Progress } from "menhir/progress";
export default function ProgressExample() {
return (
<Progress.Root
value={60}
aria-labelledby="progress-label"
class="grid w-64 grid-cols-[1fr_auto] gap-2 text-sm"
>
<span id="progress-label">Uploading</span>
<Progress.Value />
<div class="col-span-2 h-2 overflow-hidden rounded-full bg-stone-200 dark:bg-stone-800">
<Progress.Indicator class="h-full w-(--progress) bg-stone-800 dark:bg-stone-300" />
</div>
</Progress.Root>
);
}
Anatomy
<Progress.Root>
<Progress.Value />
<Progress.Indicator />
</Progress.Root>API reference
Root
<div role="progressbar">, with aria-valuemin, aria-valuemax, aria-valuenow and aria-valuetext, and data-indeterminate, data-progressing or data-complete. Its style sets --progress, the percentage of the range, such as 25%, which every element inside it inherits.
| Prop | Type | Default | Description |
|---|---|---|---|
value | number | null | — | How far the task has got, from min to max, or null while unknown. A value outside the range is clamped to it. |
min | number | 0 | The value at the start of the task. |
max | number | 100 | The value when the task is complete. |
format | Intl.NumberFormatOptions | { style: "percent" } | How aria-valuetext and Progress.Value format the value. The percent style formats the percentage of the range; any other style formats the value itself, such as { style: "unit", unit: "megabyte" } for "42 MB". For other text, such as "3 of 10 files", pass your own aria-valuetext. |
locale | Intl.LocalesArgument | — | The language to format in, else the runtime's default. Pass it when rendering on the server, so that the server and the browser format alike. |
render | (props) => JSX.Element | — | Renders the progress bar with your own component. Read once. |
Indicator
<div> for the filled part of the bar, with the Root's data-* attributes. Give it a size from --progress, such as width: var(--progress), and its own while indeterminate, when --progress is unset.
| Prop | Type | Default | Description |
|---|---|---|---|
render | (props) => JSX.Element | — | Renders the indicator with your own component. Read once. |
Value
<span> with the value as text, the same as the Root's aria-valuetext, yours if you pass one, and the Root's data-* attributes. Empty while indeterminate, unless you pass aria-valuetext.
| Prop | Type | Default | Description |
|---|---|---|---|
render | (props) => JSX.Element | — | Renders the value with your own component. Read once. |
Keyboard
| Keys | Action |
|---|---|
| Tab | Moves past the progress bar, which is not focusable: the user cannot change its value. |