Progress
A progress bar that displays the status of a task that takes a long time.
<script setup lang="ts">
import { onMounted, onUnmounted, ref } from 'vue';
import { Progress } from '@vase-ui/vue/progress';
import styles from './index.module.css';
const value = ref(20);
let interval: ReturnType<typeof setInterval> | undefined;
// Simulate changes
onMounted(() => {
interval = setInterval(() => {
value.value = Math.min(100, Math.round(value.value + Math.random() * 25));
}, 1000);
});
onUnmounted(() => clearInterval(interval));
</script>
<template>
<Progress.Root :class="styles.Progress" :value="value">
<Progress.Label :class="styles.Label">Export data</Progress.Label>
<Progress.Value :class="styles.Value" />
<Progress.Track :class="styles.Track">
<Progress.Indicator :class="styles.Indicator" />
</Progress.Track>
</Progress.Root>
</template>.Progress {
display: grid;
grid-template-columns: 1fr 1fr;
row-gap: 0.5rem;
width: 15rem;
max-width: 100%;
}
.Label {
font-size: 0.875rem;
line-height: 1.25rem;
font-weight: 400;
color: oklch(14.5% 0 0deg);
@media (prefers-color-scheme: dark) {
color: white;
}
}
.Value {
font-size: 0.875rem;
line-height: 1.25rem;
color: oklch(14.5% 0 0deg);
text-align: right;
@media (prefers-color-scheme: dark) {
color: white;
}
}
.Track {
grid-column: 1 / 3;
overflow: hidden;
height: 0.25rem;
background-color: oklch(92.2% 0 0deg);
@media (prefers-color-scheme: dark) {
background-color: oklch(26.9% 0 0deg);
}
}
.Indicator {
background-color: oklch(14.5% 0 0deg);
transition: width 500ms;
@media (prefers-color-scheme: dark) {
background-color: white;
}
}<script setup lang="ts">
import { onMounted, onUnmounted, ref } from 'vue';
import { Progress } from '@vase-ui/vue/progress';
const value = ref(20);
let interval: ReturnType<typeof setInterval> | undefined;
// Simulate changes
onMounted(() => {
interval = setInterval(() => {
value.value = Math.min(100, Math.round(value.value + Math.random() * 25));
}, 1000);
});
onUnmounted(() => clearInterval(interval));
</script>
<template>
<Progress.Root class="grid max-w-full w-60 grid-cols-2 gap-y-2" :value="value">
<Progress.Label class="text-sm font-normal text-neutral-950 dark:text-white"
>Export data</Progress.Label
>
<Progress.Value class="text-right text-sm text-neutral-950 dark:text-white" />
<Progress.Track class="col-span-2 h-1 overflow-hidden bg-neutral-200 dark:bg-neutral-800">
<Progress.Indicator class="bg-neutral-950 transition-[width] duration-500 dark:bg-white" />
</Progress.Track>
</Progress.Root>
</template>Anatomy
Import the component and assemble its parts:
<script setup lang="ts">
import { Progress } from '@vase-ui/vue/progress';
</script>
<template>
<Progress.Root :value="null">
<Progress.Label />
<Progress.Track>
<Progress.Indicator />
</Progress.Track>
<Progress.Value />
</Progress.Root>
</template>API reference
Progress.Root
Groups all parts of the progress bar and provides the task completion status to screen readers.
Without a Progress.Label, give it aria-label or aria-labelledby. With the element slot,
put text in your element, such as a Progress.Label: NVDA and JAWS can need text in a progress
bar to say its name.
Renders a <div> element with the role progressbar.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
format | Intl.NumberFormatOptions | undefined | The format of the text. With none, the text is the percent of the range. | |
getAriaValueText | ((formattedValue: string, value: number | null) => string) | undefined | Makes aria-valuetext from the text, which is '' while the progress is indeterminate, and
the value prop. With no function, an indeterminate progress has no aria-valuetext, and a
screen reader says the state in the language of the user. | |
locale | Intl.LocalesArgument | the locale of the nearest LocaleProvider, else 'en-US' | The locale of the text. |
max | number | undefined | 100 | The value at the end of the range. |
min | number | undefined | 0 | The value at the start of the range. |
value | number | null | undefined | null | The value. With no value, null or a value that is not finite, the progress is indeterminate,
as a <progress> with no value. A value out of the range counts as the nearest end of the
range. |
as | keyof HTMLElementTagNameMap | Component | GenericComponent | undefined | A tag or a component that the part renders in place of its own element, with the same
attributes and content. The element slot wins over it. |
Slots
| Slot | Slot props | Description |
|---|---|---|
default | state: ProgressRootState | The content of the part. |
element | props: Record<string, unknown>elementRef: (target: unknown) => voidstate: ProgressRootState | Renders your element in place of the element of the part. Bind props with v-bind and elementRef with :ref. |
Exposed
| Member | Type | Description |
|---|---|---|
element | HTMLDivElement | null | The element of the part, or null while it is not mounted. |
Selectors
| Selector | Description |
|---|---|
[data-indeterminate] | The progress has no value. |
[data-progressing] | The value is less than max. |
[data-complete] | The value is max. |
Progress.Track
Contains the progress bar indicator.
Renders a <div> element.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
as | keyof HTMLElementTagNameMap | Component | GenericComponent | undefined | A tag or a component that the part renders in place of its own element, with the same
attributes and content. The element slot wins over it. |
Slots
| Slot | Slot props | Description |
|---|---|---|
default | state: ProgressRootState | The content of the part. |
element | props: Record<string, unknown>elementRef: (target: unknown) => voidstate: ProgressRootState | Renders your element in place of the element of the part. Bind props with v-bind and elementRef with :ref. |
Exposed
| Member | Type | Description |
|---|---|---|
element | HTMLDivElement | null | The element of the part, or null while it is not mounted. |
Selectors
| Selector | Description |
|---|---|
[data-indeterminate] | The progress has no value. |
[data-progressing] | The value is less than max. |
[data-complete] | The value is max. |
Progress.Indicator
Visualizes the completion status of the task. It has the inline style inset-inline-start: 0,
height: inherit and a width with the percent of the range, except while the progress is
indeterminate.
Renders a <div> element.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
as | keyof HTMLElementTagNameMap | Component | GenericComponent | undefined | A tag or a component that the part renders in place of its own element, with the same
attributes and content. The element slot wins over it. |
Slots
| Slot | Slot props | Description |
|---|---|---|
default | state: ProgressRootState | The content of the part. |
element | props: Record<string, unknown>elementRef: (target: unknown) => voidstate: ProgressRootState | Renders your element in place of the element of the part. Bind props with v-bind and elementRef with :ref. |
Exposed
| Member | Type | Description |
|---|---|---|
element | HTMLDivElement | null | The element of the part, or null while it is not mounted. |
Selectors
| Selector | Description |
|---|---|
[data-indeterminate] | The progress has no value. |
[data-progressing] | The value is less than max. |
[data-complete] | The value is max. |
Progress.Value
A text element that shows the current value.
Renders a <span> element.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
as | keyof HTMLElementTagNameMap | Component | GenericComponent | undefined | A tag or a component that the part renders in place of its own element, with the same
attributes and content. The element slot wins over it. |
Slots
| Slot | Slot props | Description |
|---|---|---|
default | formattedValue: string | nullvalue: number | nullstate: ProgressRootState | The content of the part. |
element | props: Record<string, unknown>elementRef: (target: unknown) => voidstate: ProgressRootStateformattedValue: string | nullvalue: number | null | Renders your element in place of the element of the part. Bind props with v-bind and elementRef with :ref. |
Exposed
| Member | Type | Description |
|---|---|---|
element | HTMLSpanElement | null | The element of the part, or null while it is not mounted. |
Selectors
| Selector | Description |
|---|---|
[data-indeterminate] | The progress has no value. |
[data-progressing] | The value is less than max. |
[data-complete] | The value is max. |
Progress.Label
An accessible label for the progress bar. Use one in each progress bar.
Renders a <span> element.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
id | string | undefined | The progress bar names the label by this id in aria-labelledby from the mount on. To name the
bar in the server HTML too, give Progress.Root this id in aria-labelledby. An id in the
element slot does not name the bar. | |
as | keyof HTMLElementTagNameMap | Component | GenericComponent | undefined | A tag or a component that the part renders in place of its own element, with the same
attributes and content. The element slot wins over it. |
Slots
| Slot | Slot props | Description |
|---|---|---|
default | state: ProgressRootState | The content of the part. |
element | props: Record<string, unknown>elementRef: (target: unknown) => voidstate: ProgressRootState | Renders your element in place of the element of the part. Bind props with v-bind and elementRef with :ref. |
Exposed
| Member | Type | Description |
|---|---|---|
element | HTMLSpanElement | null | The element of the part, or null while it is not mounted. |
Selectors
| Selector | Description |
|---|---|
[data-indeterminate] | The progress has no value. |
[data-progressing] | The value is less than max. |
[data-complete] | The value is max. |
Progress.Status
The status of the progress bar.
'indeterminate' | 'progressing' | 'complete'
Differences from Base UI
Vase UI ports Progress from Base UI 1.9.0.
API
| Base UI | Vase UI |
|---|---|
Progress.Root prop value | The prop is optional, with the default null. A native <progress> with no value is indeterminate, and null stays valid, so the wider type removes no feature. |
Progress.Root prop aria-valuetext | aria-valuetext is an attribute, not a prop. It reaches the element with the other attributes, and it wins over the text of the part. |
Behavior
| Vase UI | Evidence |
|---|---|
The server HTML of Progress.Root, Meter.Root and Fieldset.Root has the id of the label part in aria-labelledby, when that part has no id prop. The root assumes a label until it is mounted, unless the consumer gives it an aria-label or aria-labelledby, also a blank one. A progressbar or a meter that has a label thus has its required name before the page hydrates. It has that name on a page with no client code too. Base UI adds the attribute after the page hydrates. With no label part, the server HTML of the root points at an id that no element has, and a user agent ignores that reference. |
|
With no locale prop, Meter.Root, Progress.Root, Slider.Root and NumberField.Root format their text in the locale of the nearest LocaleProvider, else in en-US. The server and the browser use the same locale, so the text does not change after the hydration. Base UI formats the text of Meter, Progress and Slider in en-US until the hydration, and then in the locale of the browser. It formats the text of Number Field in the default locale of each runtime, so the server and the browser can differ. |
The handbook gives the differences that all components share: Styling, Animation, Composition, Customization, Forms and TypeScript.