A progress indicator shows how far a process has come, such as an upload, or that one is running when its length is unknown. It is linear or circular, determinate or indeterminate, and its active indicator is flat or wavy.
Usage
ariaLabel says what is in progress.
import { createProgress } from 'material';
const progress = createProgress({ value: 40, ariaLabel: 'Uploading photo' });
document.body.append(progress.element);
<m-progress value="40" aria-label="Uploading photo"></m-progress>
import { Progress } from 'material/react';
export function Example() {
return (
<Progress value={40} ariaLabel="Uploading photo" />
);
}
<script setup lang="ts">
import { MProgress } from 'material/vue';
</script>
<template>
<MProgress :value="40" aria-label="Uploading photo" />
</template>
<script lang="ts">
import { Progress } from 'material/svelte';
</script>
<Progress value={40} ariaLabel="Uploading photo" />
import { Progress } from 'material/solid';
export function Example() {
return (
<Progress value={40} ariaLabel="Uploading photo" />
);
}
Examples
Circular, indeterminate
indeterminate shows activity without a value. A circular indicator is 40px across, 48px when
wavy; size sets it, from 24 to 240.
import { createProgress } from 'material';
const progress = createProgress({
variant: 'circular',
indeterminate: true,
ariaLabel: 'Loading messages',
});
document.body.append(progress.element);
<m-progress variant="circular" indeterminate aria-label="Loading messages"></m-progress>
import { Progress } from 'material/react';
export function Example() {
return (
<Progress variant="circular" indeterminate ariaLabel="Loading messages" />
);
}
<script setup lang="ts">
import { MProgress } from 'material/vue';
</script>
<template>
<MProgress variant="circular" indeterminate aria-label="Loading messages" />
</template>
<script lang="ts">
import { Progress } from 'material/svelte';
</script>
<Progress variant="circular" indeterminate ariaLabel="Loading messages" />
import { Progress } from 'material/solid';
export function Example() {
return (
<Progress variant="circular" indeterminate ariaLabel="Loading messages" />
);
}
Wavy and thick
shape: 'wavy' draws the active indicator as a wave, which flattens near the start and the
end. thickness is thin (4px), thick (8px) or a number of pixels.
import { createProgress } from 'material';
const progress = createProgress({
shape: 'wavy',
thickness: 'thick',
value: 60,
ariaLabel: 'Installing update',
});
document.body.append(progress.element);
<m-progress value="60" shape="wavy" thickness="thick" aria-label="Installing update"></m-progress>
import { Progress } from 'material/react';
export function Example() {
return (
<Progress value={60} shape="wavy" thickness="thick" ariaLabel="Installing update" />
);
}
<script setup lang="ts">
import { MProgress } from 'material/vue';
</script>
<template>
<MProgress :value="60" shape="wavy" thickness="thick" aria-label="Installing update" />
</template>
<script lang="ts">
import { Progress } from 'material/svelte';
</script>
<Progress value={60} shape="wavy" thickness="thick" ariaLabel="Installing update" />
import { Progress } from 'material/solid';
export function Example() {
return (
<Progress value={60} shape="wavy" thickness="thick" ariaLabel="Installing update" />
);
}
Setting the value
An action sets the value, which animates to it over 500ms; setValue(value, false) jumps. A
value out of range is clamped to 0 or max, and that is the value drawn, announced,
labelled and emitted.
import { createProgress } from 'material';
const progress = createProgress({ value: 30, buffer: 60, ariaLabel: 'Streaming video' });
document.body.append(progress.element);
function advance() {
progress.setValue(75);
}
<m-progress value="30" buffer="60" aria-label="Streaming video"></m-progress>
<script type="module">
const progress = document.querySelector('m-progress');
function advance() {
progress.value = 75;
}
</script>
import { useState } from 'react';
import { Progress } from 'material/react';
export function Example() {
const [value, setValue] = useState(30);
const advance = () => setValue(75);
return (
<Progress value={value} buffer={60} ariaLabel="Streaming video" />
);
}
<script setup lang="ts">
import { ref } from 'vue';
import { MProgress } from 'material/vue';
const value = ref(30);
function advance() {
value.value = 75;
}
</script>
<template>
<MProgress :value="value" :buffer="60" aria-label="Streaming video" />
</template>
<script lang="ts">
import { Progress } from 'material/svelte';
let value = $state(30);
function advance() {
value = 75;
}
</script>
<Progress value={value} buffer={60} ariaLabel="Streaming video" />
import { createSignal } from 'solid-js';
import { Progress } from 'material/solid';
export function Example() {
const [value, setValue] = createSignal(30);
const advance = () => setValue(75);
return (
<Progress value={value()} buffer={60} ariaLabel="Streaming video" />
);
}
buffer draws how much is ready ahead of a linear value, as for streaming media. showLabel
shows the percentage beside the indicator, and labelFormatter writes it differently. Recipes
such as an upload with progress are planned for Showcase.
API
Options
variantThe form of the indicator
'linear' | 'circular''linear'valueThe value, from 0 to max
number0maxThe value at completion
number100bufferThe buffered value of a linear indicator
number0indeterminateActivity without a value
booleanfalseshapeA flat or a wavy active indicator
'flat' | 'wavy''flat'thickness4px, 8px, or a number of pixels
'thin' | 'thick' | number'thin'sizeThe diameter of a circular indicator, from 24 to 240
number40, 48 when wavyshowStopIndicatorThe dot at the end of a determinate linear track
booleantrueshowLabelShows the value as a label
booleanfalselabelFormatterWrites the label
(value, max) => stringariaLabelWhat is in progress
string'Loading'disabledWhether it starts disabled
booleanfalseclassAdditional CSS classes
stringundefinedprefixPrefix for CSS class names
string'mtrl'Methods
getValue() / setValue(value, animate?)The value; animate is true by default
value: number, animate?: booleannumber / ProgressComponentgetMax()The maximum
numbergetBuffer() / setBuffer(value)The buffered value
value: numbernumber / ProgressComponentisIndeterminate() / setIndeterminate(indeterminate)Whether it is indeterminate
indeterminate: booleanboolean / ProgressComponentgetShape() / setShape(shape)The shape
shape: 'flat' | 'wavy'string / ProgressComponentgetThickness() / setThickness(thickness)The thickness, read in pixels
thickness: 'thin' | 'thick' | numbernumber / ProgressComponentgetSize() / setSize(size)A circular indicator's diameter
size: numbernumber | undefined / ProgressComponentshowLabel() / hideLabel()The label
ProgressComponentsetLabelFormatter(formatter)How the label is written
formatter: (value, max) => stringProgressComponentshow() / hide() / isVisible()Shows or hides it; hidden, it stops animating
ProgressComponent / booleanenable() / disable() / isDisabled()The disabled state, with aria-disabled, set the same way at creation
ProgressComponent / booleanpainted()Resolves once it has been drawn
Promise<void>on(event, handler) / off(event, handler)Adds or removes a listener
event: 'change' | 'complete', handler: FunctionProgressComponentaddClass(...classes)Adds CSS classes
...classes: string[]ProgressComponentdestroy()Stops its animations and removes it
voidEvents
changeThe value was set
{ value, max }completeThe value reached max: after the animation, or at once without one
{ value, max }The web component dispatches no events: its value and indeterminate properties are the
live state, and its attributes the first one.
Styling
The indicator is drawn on a canvas, in the theme's colors: the active and stop indicators in
--mtrl-sys-color-primary, the track in --mtrl-sys-color-secondary-container. They are read
again when the theme changes.
.mtrl-progress, .mtrl-progress--linear, .mtrl-progress--circular { }
.mtrl-progress--indeterminate, .mtrl-progress--disabled { }
.mtrl-progress__canvas, .mtrl-progress__label { }
Measurements
| Attribute | Value |
|---|---|
| Track | 4dp thin, 8dp thick; secondary-container |
| Active indicator | primary, round caps |
| Gap between the indicator and the track | 4dp |
| Stop indicator | 4dp, primary |
| Circular | 40dp, 48dp when wavy |
| Wave | 3dp amplitude and 40dp wavelength on a linear indicator (20dp indeterminate); 1.6dp and 15dp on a 40dp circle, scaled with its size |
| Value change | 500ms, linear |
| Label | Label Medium, on-surface-variant |