Progress
Shows how far a task that takes a while has come, such as an upload, an import or a sync.
Installation
pnpm dlx shadcn@latest add @silkware/progressTo copy the component by hand, install its dependencies:
pnpm add react-aria-components cnThen copy the source into components/ui/progress.tsx:
"use client"
import * as React from "react"import { cn } from "cn"import { Label as LabelPrimitive, ProgressBar as ProgressPrimitive, type LabelProps, type ProgressBarProps as ProgressPrimitiveProps,} from "@animate-ui/react/primitives/react-aria"
type ProgressContextValue = { percentage?: number isIndeterminate: boolean valueText?: string}
const ProgressContext = React.createContext<ProgressContextValue | null>(null)
function useProgress() { const context = React.useContext(ProgressContext) if (!context) { throw new Error("useProgress must be used within a Progress.") }
return context}
function ProgressContent({ children, percentage, isIndeterminate, valueText,}: ProgressContextValue & { children?: React.ReactNode}) { const context = React.useMemo( () => ({ percentage, isIndeterminate, valueText }), [percentage, isIndeterminate, valueText] )
return ( <ProgressContext value={context}> {children} <ProgressTrack> <ProgressIndicator /> </ProgressTrack> </ProgressContext> )}
function Progress({ className, children, ...props}: Omit<ProgressPrimitiveProps, "children" | "className"> & { children?: React.ReactNode className?: string}) { return ( <ProgressPrimitive data-slot="progress" className={cn("flex flex-wrap gap-3", className)} {...props} > {({ percentage, valueText, isIndeterminate }) => ( <ProgressContent percentage={percentage} valueText={valueText} isIndeterminate={isIndeterminate} > {children} </ProgressContent> )} </ProgressPrimitive> )}
function ProgressTrack({ className, ...props }: React.ComponentProps<"span">) { return ( <span className={cn( "relative flex h-1.5 w-full items-center overflow-x-hidden rounded-full bg-muted", className )} data-slot="progress-track" {...props} /> )}
function ProgressIndicator({ className, style, ...props}: React.ComponentProps<"span">) { const { percentage, isIndeterminate } = useProgress()
return ( <span data-slot="progress-indicator" className={cn("h-full bg-primary", className)} style={{ ...style, width: `${isIndeterminate ? 100 : (percentage ?? 0)}%`, }} {...props} /> )}
function ProgressLabel({ className, ...props }: LabelProps) { return ( <LabelPrimitive className={cn("text-sm font-medium", className)} data-slot="progress-label" {...props} /> )}
function ProgressValue({ className, children, ...props}: Omit<React.ComponentProps<"span">, "children"> & { children?: (value: string) => React.ReactNode}) { const { valueText } = useProgress() return ( <span className={cn( "ml-auto text-sm text-muted-foreground tabular-nums", className )} data-slot="progress-value" {...props} > {children && valueText != null ? children(valueText) : valueText} </span> )}
export { Progress, ProgressTrack, ProgressIndicator, ProgressLabel, ProgressValue,}Usage
import { Progress, ProgressLabel, ProgressValue,} from "@/components/ui/progress"<Progress value={66}> <ProgressLabel>Importing the price list</ProgressLabel> <ProgressValue /></Progress>value is a percentage from 0 to 100 unless you set minValue and maxValue. A progress bar with no ProgressLabel must have an aria-label, or screen readers announce a bar with no name.
Examples
Default
The bar alone, for a place where the surrounding text already says what is running, such as a row in a list of uploads. It still needs an aria-label.
With label and value
ProgressLabel names the task and ProgressValue shows the current value, which React Aria formats as a percentage by default. The label becomes the accessible name of the bar.
Custom scale
When the task counts things, set minValue and maxValue to the real range and pass valueLabel for the text people read, such as "12 of 40 orders". The bar fills in proportion; the label carries the number.
Indeterminate
isIndeterminate is for work that has started but cannot be measured. The bar has no aria-valuenow, so assistive technology reports it with no value. The installed component draws the indicator at full width and does not animate it, so a bare indeterminate bar looks complete; always give it a label that says what is pending, or use a Spinner instead.
Controlled
value is a plain prop: pass the number your task reports and the bar follows it. The indicator width transitions between values.
Accessibility
A progress bar is not interactive, so it has no keyboard behaviour and does not take focus.
| Key | Action |
|---|---|
| Tab | Skips the progress bar. It is not a control and is not in the tab order. |
React Aria provides:
- The
progressbarrole, witharia-valuemin,aria-valuemaxandaria-valuenowset fromminValue,maxValueandvalue. An indeterminate bar has noaria-valuenow. aria-valuetextfrom the formatted value or fromvalueLabel, so a screen reader says "12 of 40 orders" instead of "30 percent".- The name from
ProgressLabel, linked to the bar witharia-labelledby. - Number formatting for the reader's locale through
formatOptions.
You provide:
- A name, either
ProgressLabeloraria-label. Describe the task, not the widget: "Importing the price list", not "Progress". - Updates at a sensible rate. A screen reader may announce each change in value, so do not update the bar many times a second.
- A message when the task ends. A progress bar that disappears or sits at 100% is not an outcome; show a Toast or change the text.
- A way to cancel, when the task is long.
Guidelines
When to use
- For a task of known length that takes more than a second or two: a file upload, an import of the price list, a sync of several sites.
- When the person can leave and come back and needs to see how far the work has come.
When not to use
- For a wait of unknown length or under a second. Use a Spinner.
- To hold the place of content that is about to appear. Use a Skeleton, which keeps the layout steady.
- To show a value that is not progress, such as stock level or a quality score. Use a Chart or plain text with a number.
- To show a step in a flow, such as step 2 of 4. Use Breadcrumb or headings that name the steps.
Content
- Start the label with a verb in the present tense and name the object: "Importing the price list", "Uploading 2026-pricelist.xlsx".
- When the task counts things, say so in
valueLabel: "7 of 12 sites". People trust a count more than a percentage. - Write in sentence case with no full stop and no exclamation mark.
Honest progress
The bar must move because the task moved. Do not animate a bar to a fixed percentage on a timer, and do not stop at 90% to wait. If you cannot measure the work, say so with an indeterminate bar and a label, or use a spinner.
Name the task so the bar says what is running and how far it has come.
Don’t leave the bar without a name. People see a line filling up and do not know what it measures, and screen readers announce an unnamed bar.
Show a bar when you can count the work and say the count.
Don’t show a percentage for something you cannot measure, such as a reply from a supplier. Use an indeterminate bar or a spinner.
API reference
Progress
Renders a React Aria ProgressBar as a flex container that wraps the label, the value and the track. It accepts every React Aria ProgressBar prop and the props below. It always renders the track and the indicator after its children.
| Prop | Type | Default | Description |
|---|---|---|---|
value? | number | 0 | The current value, on the scale from minValue to maxValue. |
minValue? | number | 0 | The smallest value. |
maxValue? | number | 100 | The largest value. |
isIndeterminate? | boolean | false | Marks progress that cannot be measured. The bar has no value for assistive technology. |
valueLabel? | ReactNode | None | The text shown by ProgressValue and read as the value, such as 12 of 40 orders. |
formatOptions? | Intl.NumberFormatOptions | { style: "percent" } | How the value is formatted when valueLabel is not set. |
aria-label? | string | None | The name of the bar when there is no ProgressLabel. |
children? | ReactNode | None | A ProgressLabel and a ProgressValue. |
className? | string | None | Classes merged after the layout classes. |
ProgressLabel
Renders the React Aria Label of the bar, which names it for assistive technology. It accepts every React Aria Label prop.
| Prop | Type | Default | Description |
|---|---|---|---|
children? | ReactNode | None | The name of the task. |
className? | string | None | Classes merged after the label classes. |
ProgressValue
Renders a <span> with the formatted value, pushed to the end of the row, in tabular numerals. It shows nothing for an indeterminate bar.
| Prop | Type | Default | Description |
|---|---|---|---|
children? | (value: string) => ReactNode | None | A function that receives the formatted value and returns what to show instead of it. |
className? | string | None | Classes merged after the value classes. |
ProgressTrack and ProgressIndicator
Progress renders these two after its children: the track is the grey rail and the indicator is the filled part, whose width follows the percentage. You do not place them yourself. They are exported so you can read their classes, and ProgressIndicator reads its value from the nearest Progress, so it works only inside one.
| Prop | Type | Default | Description |
|---|---|---|---|
className? | string | None | Classes merged after the track or indicator classes. |
style? | CSSProperties | None | On ProgressIndicator only. The width is set after your style, so it cannot be overridden. |