Canopy Spinner — Best Practices
Use lg-spinner from @legal-and-general/canopy when an operation is taking time and
there is no meaningful progress to show, such as loading a page or submitting a form.
Apply this skill whenever you use lg-spinner or import LgSpinnerComponent.
Import
import {
LgSpinnerComponent,
LgSrAlertMessageDirective,
} from '@legal-and-general/canopy';
Add both to your module imports or standalone component's imports array.
Basic Usage
Use the StandardSpinner documentation example, with loaded, size, variant and
text supplied by your host component. Choose size and variant from the Inputs table.
@if (!loaded) {
<lg-spinner [size]="size" [variant]="variant" [text]="text ? text : null"></lg-spinner>
}
<p [lgSrAlertMessage]="loaded">Loading complete</p>
Keep the spinner visible until the process completes, then replace it with content or
navigate to the next part of the journey.
Source conflicts: The guide's Usage section uses “no meaningful progress” as its
criterion, but Don't #1 still says not to use a spinner when the process duration can be
pre-determined. The guide does not explicitly clarify known or mocked delays. Do not
infer an exception or an alternative component from these conflicting criteria.
The story's default
variant: 'generic'and additional snapshotsize: 'lg'are not
documented input values. Use only the values below. The copied example also passes
nulltotext, whereas the guide documentsstring; check this discrepancy before
using the example with strict template null checking.
Variants
Use the documented variants dark, light, color and inherit; dark is the default.
Set variant to inherit to inherit the parent element's font colour, as used by the
loading button.
Inputs
| Name | Description | Type | Default | Required |
|---|---|---|---|---|
| variant | The spinner variant | SpinnerVariant (dark, light, color, inherit) | dark | No |
| size | The size of the spinner | SpinnerSize (xs, sm, md) | md | No |
| text | The text to show under the spinner | string | undefined | No |
Dos and Don'ts
Do
- Do use spinners to help manage user expectations against technical limitations.
- Do always accompany a spinner used by itself on a page or card with a supporting
message briefly explaining the reason for the wait.
- Do always use the spinner together with
LgSrAlertMessageDirectiveto notify screen
reader users when loading finishes.
Don't
- Don't use a spinner if the duration of the process can be pre-determined, as stated
in the guide's Don't #1; see the source conflict above.
- Don't use multiple spinners in a single view.
- Don't use a spinner for the illustrated download with measurable progress
(“Downloading 45 of 127 MB, 8mb/s”). <!-- from documentation image -->
Accessibility
Use lgSrAlertMessage to announce completion, as shown in the example. Keep the supporting
message for a standalone page or card spinner. A spinner inside a component such as a
button or input does not need an accompanying message.