Menhir

Progress

View as Markdown

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

Styling
Uploading60%
ProgressExample.tsx
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.

PropTypeDefaultDescription
valuenumber | null—How far the task has got, from min to max, or null while unknown. A value outside the range is clamped to it.
minnumber0The value at the start of the task.
maxnumber100The value when the task is complete.
formatIntl.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.
localeIntl.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.

PropTypeDefaultDescription
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.

PropTypeDefaultDescription
render(props) => JSX.Element—Renders the value with your own component. Read once.

Keyboard

KeysAction
TabMoves past the progress bar, which is not focusable: the user cannot change its value.