Spin

A Spin shows that something is loading: four turning dots, on their own, over content that is waiting, or over the whole page. It is not interactive and never takes focus.

Import
import { Spin } from 'svelte-ant-design';
Links
src/lib/Spin Report an issue Component README

When to use

  • Use a Spin while a block or a page waits for data. Wrap the content in it when a card or a list is loading; use it alone for a small spot.
  • For a load that is usually quick, set delay so the indicator does not flash. If you know how far along it is, use percent.
  • Use fullscreen only for a page loader, and say what is going on with description, because a screen reader hears nothing else.

Examples

spinning
A standalone Spin: only the indicator
spinning is true

Basic

A Spin with no children is only the indicator. spinning turns it on and off; not spinning, it renders nothing and takes no room.

size="small" (14 px)
size="medium" (20 px, the default)
size="large" (32 px)
size="default" (an alias of medium)

Sizes

small, medium and large set the box of the dots to 14, 20 and 32 px. The value default is accepted as an alias of medium.

spinning
Spin with children: the content is dimmed and ignores the mouse
Loading the report

The report has three rows.

The button was pressed 0 times

Embedded mode

Content inside the Spin is dimmed while it spins, and the indicator is centered over it. The mouse and the text selection are blocked, the keyboard is not: press Tab to the button and Enter. A Spin never makes its content inert.

description as a string, standalone
Loading
description as a snippet, standalone
Saving (this takes a moment)
description over embedded content
Loading the table
Rows that are being loaded.

Description

description is shown under the indicator, as a string or as a snippet. It is also the text that a screen reader announces.

delay={500}: the indicator waits half a second
A load shorter than the delay never shows the indicator
The content of the panel.
Nothing has been loaded yet

Delay

delay holds the indicator back, so a quick load does not flash it. Every time spinning becomes true the wait starts again; turning it off hides the indicator at once.

indicator: an icon the example turns
Loading
indicator: a large icon
indicator: text

Custom indicator

indicator replaces the dots with a snippet. It sits in a box of the dot size whose font size is the same, so an icon in em scales with size. The Spin does not turn it.

percent: a number from 0 to 100
Uploading
percent="auto": an indeterminate ring, no value
Preparing
percent with size="large"

Progress

percent draws a ring that fills from 12 o'clock; it is a progressbar named by the description. 'auto' is an indeterminate ring that turns, with no value. A custom indicator wins over percent.

fullscreen: a dimmed backdrop over the viewport, for three seconds spinning is false

Fullscreen

fullscreen draws a dimmed backdrop over the whole viewport with the indicator in the middle, for a page loader. It stays where the component is (position: fixed): put it near the root of the application. It has no focus trap and does not lock the scroll.

classNames: a class for each part (the CSS is in this example)
Loading
styles: inline styles, custom properties included
Loading
class and style go to the root; container is the covered content
Loading
Covered content

Classes and styles

classNames and styles address the parts root, section, indicator, description and container; class and style go to the root. Inline styles win over the component's own, and custom properties such as --ads-spin-color work.

API

PropertyDescriptionTypeDefault
spinningWhether the Spin is active. spinning={undefined} counts as the default, true. Standalone, not spinning (or still in the delay) renders nothing; embedded, the content is shown as it is.booleantrue
delayMilliseconds to wait, every time spinning becomes true (also at mount), before the indicator appears. Turning spinning off cancels the wait and hides at once; a repeated true starts no second timer. A negative or non-finite number throws a RangeError in development and means no delay in production.number—
sizeSize of the dot box: 14, 20 or 32 px. default is a compatibility alias of medium. Another value throws a RangeError in development and falls back to medium in production.'small' | 'medium' | 'large' | 'default''medium'
descriptionText or content under the indicator. A string is text, never HTML; an empty string counts as not given. It is the status message that a screen reader announces and the name of the progress ring.string | Snippet—
indicatorReplaces the default dots. Drawn in a box of the dot size, with the same font size and the Spin color. The component does not turn it. Hidden from assistive technology.Snippet—
percentDraws a progress ring in place of the dots. A number is clamped to 0 to 100; 'auto' is an indeterminate ring that turns, with no aria-valuenow and no timer. A value that is not a valid number, or of another type, throws a RangeError in development and is ignored in production. A custom indicator wins.number | 'auto'—
fullscreenA dimmed backdrop over the viewport with the indicator in the middle. Drawn in place with position: fixed, so it is relative to the viewport only when no ancestor has a transform, filter or contain. It blocks the pointer, has no focus trap and does not lock the scroll. It fades in and leaves at once.booleanfalse
childrenEmbedded mode: the content the Spin covers. While spinning it has half opacity, ignores the pointer and the text selection, and gets aria-busy. It stays focusable and readable. Together with fullscreen it is drawn as it is, not dimmed.Snippet—
classNamesExtra classes for the parts root, section (indicator and description together), indicator, description and container (the covered content, embedded mode only), appended to the component's own. A standalone Spin has one element for root and section.Partial<Record<'root' | 'section' | 'indicator' | 'description' | 'container', string>>—
stylesInline styles for the same parts. Property names are kebab-case or custom properties, numbers are written as they are (no automatic px). They win over the component's styles.Partial<Record<'root' | 'section' | 'indicator' | 'description' | 'container', Record<string, string | number>>>—
classAn additional CSS class for the root.string—
styleInline style of the root; styles.root is written after it.string—
native attributesNative attributes of the root <div> (id, title, data-*, aria-*, handlers) are forwarded to it. aria-label and aria-labelledby go to the status element (the section, in embedded mode), where they name a Spin that has no description. role belongs to the component.HTMLAttributes<HTMLDivElement>—
Differences from Ant Design: description replaces the deprecated tip, classNames.root replaces wrapperClassName, and size="default" is only an alias of medium. percent="auto" is an indeterminate ring that turns, not a simulated progress. indicator is a snippet, and classNames and styles take objects, not functions. There is no Spin.setDefaultIndicator: a default indicator and size are reserved for ConfigProvider in v1.1.

Semantic parts

PartDescription
rootThe outer element. Standalone and fullscreen: the status element itself.
sectionThe indicator and the description together. The same element as the root when standalone; a separate one, centered over the content, when embedded or fullscreen.
indicatorThe box of the dots, the ring or the custom indicator.
descriptionThe text under the indicator.
containerThe covered content. Embedded mode only (and with fullscreen plus children).

Design tokens

TokenDescriptionDefault
--ads-spin-dot-sizeBox of the dots of a medium Spin.20px
--ads-spin-dot-size-smBox of the dots of a small Spin.14px
--ads-spin-dot-size-lgBox of the dots of a large Spin.32px
--ads-spin-gapSpace between the indicator and the description.12px
--ads-spin-colorColor of the dots, the ring and a custom indicator.#1677ff
--ads-spin-description-colorColor of the description. tokens-accessible.css darkens it to #1668dc to keep 4.5:1 as text.#1677ff
--ads-spin-container-opacityOpacity of the covered content while spinning.0.5
--ads-spin-durationOne turn of the dots or of the indeterminate ring. With prefers-reduced-motion it is 2.5 times longer.1.2s
--ads-spin-pulse-durationOne pulse of a dot. With prefers-reduced-motion it is 2.5 times longer.1s
--ads-spin-mask-bgBackdrop of a fullscreen Spin. tokens-accessible.css sets 60% black, so white text on it keeps 4.5:1 over a white page.rgba(0, 0, 0, 0.45)
--ads-spin-fullscreen-colorColor of the indicator and the description on the backdrop.#ffffff
--ads-spin-fullscreen-z-indexLayer of the backdrop (the base layer of Ant Design popups).1000
--ads-spin-ring-trackTrack of the progress ring.rgba(0, 0, 0, 0.06)

Accessibility

  • The dots, the drawing of the ring and a custom indicator are hidden from assistive technology. What a screen reader hears is the status element: role="status", a polite live region, with the text of description.
  • A Spin with no description is silent. Name it with aria-label or aria-labelledby; in development a spinning Spin with neither logs one warning.
  • In embedded mode the covered content gets aria-busy="true" while spinning. It is not made inert or hidden: the mouse and the text selection are blocked, the keyboard and a screen reader are not, so an action that must not run twice has to guard itself.
  • The progress ring is role="progressbar" with aria-valuenow, named by the description or by aria-label. An indeterminate ring ('auto') has no value.
  • The fullscreen backdrop blocks the pointer but has no focus trap and does not lock the scroll, so Tab still reaches the page behind it.
  • By default the colours are Ant Design's own. With tokens-accessible.css, and in the dark theme, the dots and the ring keep 3:1 and the description 4.5:1 against the page, and white text on the fullscreen backdrop keeps 4.5:1. prefers-reduced-motion slows the turn instead of stopping it, and in forced-colors modes such as Windows High Contrast the dots and the ring are drawn with system colours.
  • Checked with a real screen reader (Orca with Firefox): it reads the description as a status, a Spin named by aria-label, the content an embedded Spin covers, the progress ring with its name and its value in percent (and without a value when it is indeterminate), and a fullscreen Spin that hides nothing behind it. Not checked: whether a screen reader announces the status when it appears (the Orca setup does not speak a live region that is inserted into the page), NVDA, JAWS and VoiceOver.