# Progress

> A bar that shows how far a task has come; for an upload, the steps of a wizard or how full something is.

Source: https://shadleaf.dev/1.2.0/components/progress/

A horizontal bar that fills up as a task gets done, or shows how much of something is used. It is a native `<progress>`
element, so screen readers announce it as a progress bar with its value.

**Example: Progress.**

```html
<sl:progress value="33" aria-label="Upload progress"/>
```

## When to use

- An upload or an import whose progress the server reports.
- The steps of a form spread over several pages: step 3 of 8.
- How much of something is used or left, such as storage or stock.

Use something else for:

- Something that is loading, without a share to show: a [spinner](https://shadleaf.dev/1.2.0/components/spinner.md) or a [skeleton](https://shadleaf.dev/1.2.0/components/skeleton.md).
- The progress of files the user uploads: the [file upload](https://shadleaf.dev/1.2.0/components/file-upload.md) shows it on each file.

## Value and maximum

`value` is how far the task has come, out of `max`: 100 unless you set it. Both are the native element's attributes, so
`th:value` and `th:max` set them from an expression. A value above the maximum shows a full bar.

**Example: Out of another maximum.**

```html
<sl:progress value="3" max="8" aria-label="Steps done"/>
```

**Example: Values from an expression.**

```html
<sl:progress th:value="${task.done}" th:max="${task.total}"
             th:aria-label="${task.name}"/>
```

## A name

A progress bar needs an accessible name, or rendering fails: an `aria-label`, or an `aria-labelledby` with the id of a
visible label. In a [field](https://shadleaf.dev/1.2.0/components/field.md), the field label is that label:

**Example: With a label.** aria-labelledby names the bar after the visible label.

```html
<sl:field>
  <sl:field-label id="upload-label">Upload progress</sl:field-label>
  <sl:progress value="66" aria-labelledby="upload-label"/>
  <sl:field-description>8 of 12 MB</sl:field-description>
</sl:field>
```

## Indeterminate

Without a value the bar is indeterminate: it shows an empty track, as shadcn's, and a screen reader announces a progress
bar without a value. A `th:value` whose expression is null still writes an empty `value` attribute, which the browser
reads as 0; for a value that may be null, use `th:attr`, which leaves the attribute out:

```html
<sl:progress th:attr="value=${export.percent}" aria-label="Export"/>
```

**Example: Indeterminate.** Without a value, the bar says that work goes on without saying how far it is.

```html
<sl:progress aria-label="Preparing the export"/>
```

## Updating with htmx

The server renders the value, so to show progress while a task runs, swap the bar in again: poll a fragment with
`hx-trigger="every 1s"` around it, or send it out of band with each response. A progress element is not a live region;
put the text that matters (such as "Import done") in a status message or a [toast](https://shadleaf.dev/1.2.0/components/toast.md).

## Everything else passes through

**Example: Pass-through attributes.** Anything that is not a prop lands on the progress element; class is appended.

```html
<sl:progress value="80" aria-label="Storage used" class="app-wide" id="storage" data-testid="storage"/>
```

## Attributes

Attributes of `<sl:progress>`: A bar that shows how far a task has come: a native `progress` element, so the browser gives it the progressbar role and its value and range. `value` and `max` (100 unless set) pass through as attributes, as every attribute that is not a prop; `class` is appended to `progress`. Without a value it is indeterminate: an empty track. It needs an accessible name: an `aria-label`, or an `aria-labelledby` with the id of a visible label.

`sl:progress` declares no props; every attribute passes through.

## Styling hooks

The classes and attributes your own CSS can select to restyle the component, as explained in
[your own CSS rules](https://shadleaf.dev/1.2.0/guides/adjustability.md#5-your-own-css-rules). The bar is the element itself; the indicator is
the browser's `::-webkit-progress-value` (Chrome, Safari) and `::-moz-progress-bar` (Firefox), each in a rule of its
own.

Styling hooks of `<sl:progress>`.

**Parts**

| Class | Element |
| --- | --- |
| `.progress` | `<progress>` |
