Primitives
Progress
A bar that reflects the completion progress of a task.
Press Advance until the bar fills: it reflects data-value against data-min / data-max, and data-state moves from loading to complete at max, where the stylesheet turns it green and announceCompletion reads the completion out.
Pass a numeric value for a determinate bar, or null for indeterminate ("loading…"). The directive owns ARIA + state; the visual fill is yours via [forProgressIndicator].
When to choose
- Progress:
role="progressbar", for a task advancing toward completion.valueacceptsnullfor the indeterminate "working…" state, andannounceCompletionannounces the end of the task. - Meter:
role="meter", for a measurement inside a known range (disk used, battery, score), always determinate and bucketed into quality bands. Screen readers announce the two roles differently, so the choice is meaning rather than appearance: if the number is not going anywhere, it is a meter.
Anatomy
<div forProgress [value]="uploaded()" [max]="100" announceCompletion>
<div forProgressIndicator></div>
</div>
Examples
Indeterminate
A null value puts the bar in indeterminate mode, for loading states whose duration cannot be predicted. A non-finite value does the same, as on <progress>, so a ratio such as loaded() / total() * 100 read while total() is still 0 shows a busy bar rather than NaN. In that mode aria-valuenow is omitted and data-state reflects indeterminate.
Custom value label
getValueLabel maps value and max to a human string used for aria-valuetext, so screen readers announce '84 MB of 200 MB' instead of a bare number. The same function feeds the visible caption.
API
ForProgress
| Property | Type | Description |
|---|---|---|
value | input | Current progress in [0, max] (one-way; display-only). null or a non-finite number (NaN, ±Infinity) = indeterminate.Default: null |
max | input | Upper bound. A non-positive or non-finite max falls back to 1 for ARIA so aria-valuemax always exceeds aria-valuemin (0).Default: 100 |
getValueLabel | input | Override for aria-valuetext (e.g. "Step 3 of 5").Default: — |
announceCompletion | input | Announce once via aria-live on the loading→complete transition: the aria-valuetext when getValueLabel is set, else the scope's completeAnnouncement text (English fallback Complete).Default: false (or the scope default) |
ariaLabel | input | Accessible name for the progressbar. Prefer a visible label referenced via aria-labelledby when one exists.Default: null |
| Data attribute | Values | |
|---|---|---|
data-state | indeterminate | loading | complete | |
data-value | clamped value (absent while indeterminate) | |
data-min | 0 | |
data-max | the max value | |
data-percentage | 0–100 (absent while indeterminate) |
ForProgressIndicator
Visual fill paired with [forProgress]. Reflects the same state so width / transform can be driven from CSS, plus the --for-progress-percentage custom property (e.g. 25%) for use directly in transform / width.
| Data attribute | Values | |
|---|---|---|
data-state | indeterminate | loading | complete | |
data-value | clamped value (absent while indeterminate) | |
data-min | 0 | |
data-max | the max value | |
data-percentage | 0–100 (absent while indeterminate) |
Scoped defaults
provideForProgressDefaults configures progress defaults for an injector subtree, either at the application root or in any component's providers array. Partial overrides inherit unspecified keys from the parent scope (or the library fallbacks at the root).
| Key | Library fallback | Meaning | |
|---|---|---|---|
announceCompletion | false | Whether bars that don't set announceCompletion themselves announce once through aria-live when they reach complete. | |
completeAnnouncement | 'Complete' | Text announced on that transition when the bar has no aria-valuetext (no getValueLabel). A bar with one announces its value text. |
A bar's own announceCompletion input wins over the scope default.
completeAnnouncement is spoken by a screen reader, so translate it here to localize the completion announcement of every bar in the scope. It accepts a string, or a function returning one that is called each time the announcement fires, so a function that reads a language signal announces in the current language:
import { signal, type ApplicationConfig } from '@angular/core';
import { provideForProgressDefaults } from 'forty-cdk/defaults';
export const language = signal<'en' | 'es'>('en');
const completeText = { en: 'Complete', es: 'Completado' } as const;
export const appConfig: ApplicationConfig = {
providers: [
provideForProgressDefaults({
announceCompletion: true,
completeAnnouncement: () => completeText[language()],
}),
],
};
A fixed language takes a plain string, provideForProgressDefaults({ completeAnnouncement: 'Completado' }). To read translations from a service, pass the overrides as a factory, as Localizing default text shows.
Accessibility
Implements the WAI-ARIA progressbar role. The APG has no progress bar pattern, and its Meter pattern is not one: a meter must not be used to show progress.
role="progressbar"is announced as "progressbar" with the current value as a percentage (or youraria-valuetextifgetValueLabelis set).- Name the bar.
role="progressbar"requires an accessible name and the directive binds none on its own: reference the visible caption witharia-labelledby(the file name of an upload, say), or setariaLabelwhen nothing on screen says what is progressing. - Indeterminate omits
aria-valuenow. Per spec, the absence ofaria-valuenowis what tells AT the bar is indeterminate. The directive enforces this;data-state="indeterminate"is the CSS hook. - Announce sparingly.
announceCompletionis opt-in; only enable it on flows where the user explicitly waits for completion (uploads, submissions). For background activity, the silent state change is enough. - Keep the bar focusable only if it has actions. A vanilla
[forProgress]is non-interactive and should not be in the tab order.
Styling
forty-cdk ships no styles: put your own class on each piece and key your CSS off the data-* attributes listed under API, not off the for* selectors (Styling forty-cdk explains why).
CSS custom properties
| Property | Meaning | |
|---|---|---|
--for-progress-percentage | Completion as a CSS percentage (e.g. 25%), set on [forProgressIndicator]. Absent while indeterminate (value === null). |
.indicator[data-state='loading'] {
width: var(--for-progress-percentage, 0%);
}
Wrapping in a design system
Subclass the root and re-provide FOR_PROGRESS_CONTEXT with useExisting pointing at the subclass, since Angular does not inherit a directive's providers; Wrapping non-form roots walks the pattern.