Design
We use Progress Bars to tell the user something is happening and how long it will take. There are two visual styles: default and long (for long-running actions).
Default | Long | Purpose |
---|---|---|
The default state for progress bars is active; and progress is shown as a percentage. For actions expected to take a long time, activity is shown with animation. | ||
Indeterminate state is used when an action is running but there is no way to estimate how long it will take. | ||
Static state - for long-running actions which are paused and can be resumed, or for progress measured across days and months rather than during the current session. | ||
|
|
Progress bars can be set to a range of sizes, or simply allowed to run to full width of their container. |
Assistive and visible text can be added as well as the progress bar. | ||
Errors - sometimes it is useful to show status information with an error. | ||
n/a | Page Context progress bar - a thin bar that sits at the top of the current page. Commonly used with SPAs while data is loading. Note that Page Context Progress Bars are always 100% width and thin style. |
Code
Progressbar shows a percentage progress state. Application code needs to pre-calculate the value to an integer from 0 to 100 inclusive. There is a helper function in ACE for doing this in JavaScript.
Example | Element | Code |
---|---|---|
Progress Bar set to 10% progress |
|
|
Progress Bar set to indeterminate state |
|
|
Long variant is set with a variant class. |
|
|
|
Sizes are set with a variant class. Supported sizes: xxsmall , xsmall , small , medium , large , xlarge , xxlarge , fullwidth |
|
While assistive technology will generally inform the user of percentage progress, you can add alternative text using aria-valuetext . This can optionally be shown visibly as well; and if absoultely necessary the visible text can vary from the aria-valuetext (if in doubt simply match them). |
|
|
When setting an error state is it recommended that both visible and accessible text are provided with details. Note the state attribute must be set to error . |
|
|
Hidden Progress Bar | You can pre-render a hidden Progress Bar by setting the attribute aria-hidden="true" . You can then show it using the JavaScript show method. |
|
JavaScript
Methods
Function | Arguments | Description | Example |
---|---|---|---|
setProgress |
elementSelector, options object | Sets the Progress Bar's progress percentage and state |
To set a progress bar to 10% progress (
To set indeterminate state:
To change from indeterminate to active, update state and indicate the current progress:
To set a Progress Bar to error state with visible and assistive text:
|
hide |
elementSelector | Hide a Progress Bar |
|
show |
elementSelector | Show a hidden Progress Bar |
|
calculatePercent |
now, max | Helper method - calculates a simple percentage passing in the 'now' and 'max' values. |
|