Progress
Show a task’s progress, or an indeterminate state while its progress is unknown.
import { Component } from "@angular/core"
import {
Progress,
ProgressIndicator,
ProgressLabel,
ProgressTrack,
ProgressValue,
} from "@ui-sdk/angular/progress"
@Component({
imports: [
Progress,
ProgressIndicator,
ProgressLabel,
ProgressTrack,
ProgressValue,
],
template: `
<div uiProgress [value]="60">
<span uiProgressLabel>Exporting video</span>
<span uiProgressValue></span>
<div uiProgressTrack>
<div uiProgressIndicator></div>
</div>
</div>
`,
})
class Example {}
export { Example }Installation
npm install @ui-sdk/angular @ui-sdk/coreComposition
Use the following composition to build Progress:
uiProgress
├── uiProgressLabel
├── uiProgressValue
└── uiProgressTrack
└── uiProgressIndicatoruiProgressholds the value and range.uiProgressLabelgives it a visible name. You can usearia-labelon the root instead.uiProgressValuedisplays the formatted value.uiProgressTrackgives the bar its size, anduiProgressIndicatorfills it.
The value is already part of the root's accessible description. The visible value is hidden from screen readers to avoid reading it twice.
Usage
Import the parts and put them together:
<div uiProgress [value]="40">
<span uiProgressLabel></span>
<span uiProgressValue></span>
<div uiProgressTrack>
<div uiProgressIndicator></div>
</div>
</div>Build Your Own
@ui-sdk/angular/progress comes with a ready-made Progress. If you'd like to build your own, with your own names, start from the progress primitive in @ui-sdk/core:
import { Directive, inject, input } from "@angular/core"
import { progress } from "@ui-sdk/core/progress"
import { usePart, usePrimitive } from "@ui-sdk/angular/primitive"
@Directive({ selector: "[appUpload]" })
class Upload {
readonly value = input<number>()
readonly handle = usePrimitive(progress, () => ({ value: this.value() }))
readonly state = usePart(this.handle, "root").state
}
@Directive({ selector: "[appUploadLabel]" })
class UploadLabel {
readonly state = usePart(inject(Upload).handle, "label").state
}
@Directive({ selector: "[appUploadValue]", exportAs: "appUploadValue" })
class UploadValue {
readonly state = usePart(inject(Upload).handle, "value").state
}
@Directive({ selector: "[appUploadTrack]" })
class UploadTrack {
readonly state = usePart(inject(Upload).handle, "track").state
}
@Directive({ selector: "[appUploadBar]" })
class UploadBar {
readonly state = usePart(inject(Upload).handle, "indicator").state
}
export { Upload, UploadBar, UploadLabel, UploadTrack, UploadValue }import { Component } from "@angular/core"
import {
Upload,
UploadBar,
UploadLabel,
UploadTrack,
UploadValue,
} from "./upload"
@Component({
selector: "app-upload-example",
imports: [Upload, UploadBar, UploadLabel, UploadTrack, UploadValue],
template: `
<div appUpload [value]="40">
<span appUploadLabel>Uploading photos</span>
<span appUploadValue #uploadValue="appUploadValue">{{
uploadValue.state().text
}}</span>
<div appUploadTrack>
<div appUploadBar></div>
</div>
</div>
`,
})
export class UploadExample {}uiProgressValue fills an empty element with the formatted value. A directive of your own leaves its content to you, so show state().text in it, as above.
Connect the other slots the same way, each with usePart. Each part keeps the behavior, state and data attributes of its ready-made counterpart: the root is the progressbar, and the indicator sets its width from the value. See Rendering Primitives and Custom Parts for more.
Indeterminate
Leave out value when you do not know how much work is complete. Every part gets data-indeterminate, and the root has no aria-valuenow.
The indicator has no inline width in this state. This example sweeps a short highlight across the track, and shows a still, full-width fill when reduced motion is on.
import { Component } from "@angular/core"
import {
Progress,
ProgressIndicator,
ProgressLabel,
ProgressTrack,
} from "@ui-sdk/angular/progress"
@Component({
imports: [Progress, ProgressIndicator, ProgressLabel, ProgressTrack],
template: `
<div uiProgress [value]="null">
<span uiProgressLabel>Connecting to server</span>
<div uiProgressTrack>
<div uiProgressIndicator></div>
</div>
</div>
`,
})
class Example {}
export { Example }Changing the Value
Pass the latest value as your task progresses. The parts get data-progressing while the value is below max, and data-complete when it reaches the end.
import { Component, signal } from "@angular/core"
import { useLog } from "./log"
import {
Progress,
ProgressIndicator,
ProgressLabel,
ProgressTrack,
ProgressValue,
} from "@ui-sdk/angular/progress"
@Component({
imports: [
Progress,
ProgressIndicator,
ProgressLabel,
ProgressTrack,
ProgressValue,
],
template: `
<div data-slot="stack">
<div data-slot="controls">
<button
type="button"
[attr.aria-disabled]="uploaded() >= total"
(click)="uploadNext()"
>
Upload Next
</button>
<button type="button" (click)="reset()">Reset</button>
</div>
<div uiProgress [value]="(uploaded() / total) * 100">
<span uiProgressLabel>Uploading photos</span>
<span uiProgressValue></span>
<div uiProgressTrack>
<div uiProgressIndicator></div>
</div>
</div>
</div>
`,
})
class Example {
readonly total = 5
readonly log = useLog()
readonly uploaded = signal(1)
uploadNext() {
if (this.uploaded() >= this.total) {
return
}
this.uploaded.update((v) => v + 1)
this.log(`Uploaded ${this.uploaded()} of ${this.total} photos`)
}
reset() {
this.uploaded.set(0)
this.log("Reset to 0 photos")
}
}
export { Example }Progress displays your state; it has no (beforeValueChange) callback.
Bounds
min and max default to 0 and 100. A value outside that range is clamped for the fill, the percentage and aria-valuenow, but the state's value and a format other than percent keep it as you passed it. A value of 3 between 1 and 5 fills half the track.
import { Component } from "@angular/core"
import {
Progress,
ProgressIndicator,
ProgressLabel,
ProgressTrack,
ProgressValue,
} from "@ui-sdk/angular/progress"
@Component({
imports: [
Progress,
ProgressIndicator,
ProgressLabel,
ProgressTrack,
ProgressValue,
],
template: `
<div uiProgress [value]="3" [min]="1" [max]="5">
<span uiProgressLabel>Account setup, step 3 of 5</span>
<span uiProgressValue></span>
<div uiProgressTrack>
<div uiProgressIndicator></div>
</div>
</div>
`,
})
class Example {}
export { Example }Format and Locale
Pass Intl.NumberFormat options to format for units or decimal places. A function can return custom text, such as the time remaining.
import { Component } from "@angular/core"
import {
Progress,
ProgressIndicator,
ProgressLabel,
ProgressTrack,
ProgressValue,
} from "@ui-sdk/angular/progress"
@Component({
imports: [
Progress,
ProgressIndicator,
ProgressLabel,
ProgressTrack,
ProgressValue,
],
template: `
<div data-slot="stack">
@for (item of bars; track item.label) {
<div
uiProgress
[value]="item.value"
[max]="item.max"
[format]="item.format"
[locale]="item.locale"
>
<span uiProgressLabel>{{ item.label }}</span>
<span uiProgressValue></span>
<div uiProgressTrack>
<div uiProgressIndicator></div>
</div>
</div>
}
</div>
`,
})
class Example {
readonly bars = [
{
label: "Download",
value: 120,
max: 250,
format: { style: "unit", unit: "gigabyte" },
},
{
label: "Video render",
value: 87.25,
format: { style: "percent", maximumFractionDigits: 1 },
},
{
label: "Backup",
value: 45,
max: 60,
format: (minutes: number) => `${60 - minutes} min left`,
},
{ label: "Synchronisierung", value: 40, locale: "de-DE" },
] satisfies {
label: string
value: number
max?: number
format?: Intl.NumberFormatOptions | ((value: number) => string)
locale?: string
}[]
}
export { Example }A percent format reports the value's position between min and max. Other formats use the value itself.
locale controls digits and separators. If you omit it, the component reads the page's language after it mounts, with the browser's language as a fallback. The initial server and client render use English.
Set dir="rtl" on the surrounding content to fill the track from the right.
Value Label
Use getValueLabel to give screen readers more context than the visible number. Its details include formatted, percent, min, and max. Handle a null value when the task can be indeterminate; percent is also null and formatted is empty then.
import { Component } from "@angular/core"
import {
Progress,
ProgressIndicator,
ProgressLabel,
ProgressTrack,
ProgressValue,
type GaugeLabelDetails,
} from "@ui-sdk/angular/progress"
@Component({
imports: [
Progress,
ProgressIndicator,
ProgressLabel,
ProgressTrack,
ProgressValue,
],
template: `
<div uiProgress [value]="3" [max]="12" [getValueLabel]="valueLabel">
<span uiProgressLabel>Copying files</span>
<span uiProgressValue>3 of 12</span>
<div uiProgressTrack>
<div uiProgressIndicator></div>
</div>
</div>
`,
})
class Example {
readonly valueLabel = (value: number | null, details: GaugeLabelDetails) =>
`${value} of ${details.max} files, ${details.formatted}`
}
export { Example }Use Meter for a reading such as storage used, rather than a task that will finish.
Custom Rendering
See Parts and Composition for changing a part's element or reading its state. Use format for text that should be shared by the visible value and screen readers.
Styling
Give the track a height, background, and width. The indicator sets its width as an inline percentage of the track. Style data-indeterminate for a task whose progress is unknown, since the indicator has no width then, and data-complete once the task finishes. Both styling options are shown in each example's Code tab.
Each part has a data-slot, such as progress-indicator, and its state attributes are listed under Data Attributes.
Progress
The root exposes a CSS variable for positioning other content alongside the reading.
| Variable | What it holds |
|---|---|
--progress-value | Where the value sits between min and max, as a percentage, like 40%. Unset while indeterminate. |
Data Attributes
Progress
[data-slot="progress"]
| Attribute | What it means |
|---|---|
data-indeterminate | Present while the value is null: the task is under way, but how far is unknown. |
data-progressing | Present while the value is below max. |
data-complete | Present once the value reaches max. |
ProgressLabel
[data-slot="progress-label"]
| Attribute | What it means |
|---|---|
data-indeterminate | Present while the value is null: the task is under way, but how far is unknown. |
data-progressing | Present while the value is below max. |
data-complete | Present once the value reaches max. |
ProgressValue
[data-slot="progress-value"]
| Attribute | What it means |
|---|---|
data-indeterminate | Present while the value is null: the task is under way, but how far is unknown. |
data-progressing | Present while the value is below max. |
data-complete | Present once the value reaches max. |
ProgressTrack
[data-slot="progress-track"]
| Attribute | What it means |
|---|---|
data-indeterminate | Present while the value is null: the task is under way, but how far is unknown. |
data-progressing | Present while the value is below max. |
data-complete | Present once the value reaches max. |
ProgressIndicator
[data-slot="progress-indicator"]
| Attribute | What it means |
|---|---|
data-indeterminate | Present while the value is null: the task is under way, but how far is unknown. |
data-progressing | Present while the value is below max. |
data-complete | Present once the value reaches max. |
API Reference
Each option below is an input on the directive.
Progress
min?number- The lowest value.
max?number- The highest value.
format?NumberFormat- How the value reads, for screen readers and the Value part:
Intl.NumberFormatoptions, or a function of the value. A percent style shows where the value sits betweenminandmax; any other style shows the value itself, like{ style: "unit", unit: "gigabyte" }. locale?string- The locale the value is formatted in. Defaults to the page's
lang, or the browser's language without one, once the page is interactive. Server markup uses English until then, so it never disagrees with the client. getValueLabel?((value: number | null, details: GaugeLabelDetails<number | null>) => string)- The text screen readers announce for the value, when the formatted value says too little, like "3 of 12 files". It receives the value, null while a progress bar is indeterminate, and details: the
formattedvalue, itspercent,minandmax. value?number | null- How far the task has come, between
minandmax. Null means it's under way but how far is unknown, and the bar is indeterminate. debug?boolean- Logs every state change with its reason to the console, in development builds.
State
What each part's state() signal holds. Every part gets the same state.
valuenumber | null- The value, or null while indeterminate.
percentnumber | null- Where the value sits between
minandmax, from 0 to 100, or null while indeterminate. statusProgressStatus- Whether the progress is unknown, under way, or done.
uiProgressValue adds the formatted text:
valuenumber | null- The value, or null while indeterminate.
percentnumber | null- Where the value sits between
minandmax, from 0 to 100, or null while indeterminate. statusProgressStatus- Whether the progress is unknown, under way, or done.
textstring- The formatted value, like "40%". Empty while indeterminate.
Accessibility
Name the component with uiProgressLabel or aria-label. It exposes the range and formatted value through the progressbar role. Use getValueLabel when that value needs more explanation.
Tested Behavior
Every line below is an automated test.
- A progress bar is named by its label and reads its value.
- The value part shows the formatted value.
- The indicator is as wide as the value.
- A new value updates the bar.
- Every part says whether the task is under way, done, or unknown.
- An indeterminate bar has no value.
- A unit format reads the value itself.
- A value label replaces the formatted value for screen readers.
- A value above the maximum reads as the maximum.
Runs in React, Vue and web components.