Skeleton
vig-skeleton vigSkeleton
import { Skeleton, VigSkeleton } from '@vigdx/ui/skeleton';Shapes
shape is text (default), rect or circle . Text skeletons render lines bars, the last one shorter; width and height take any CSS length.
Sizing with the font
1em tall, so wrap them in the text style they stand in for. Set animated to false for a static placeholder; the pulse also stops for users who prefer reduced motion.
Loading a card
ariaLabel announces the whole placeholder; the other skeletons stay silent.
Skeleton directive
Put vigSkeleton on the real markup and it becomes its own placeholder while the data loads, with no second skeleton tree to keep in sync:
<h2 [vigSkeleton]="loading()">{{ user()?.name }}</h2>
<p [vigSkeleton]="loading()" vigSkeletonLines="3">{{ user()?.bio }}</p>
<img [vigSkeleton]="loading()" vigSkeletonShape="circle"
[attr.src]="user()?.avatar" alt="" width="48" height="48" /> While vigSkeleton is true the element keeps its box, hides its content and shows the skeleton look: one bar per line for text, a filled block for vigSkeletonShape="rect" and "circle". An empty element is vigSkeletonLines lines tall (1lh each); vigSkeletonWidth and vigSkeletonHeight size it while loading, and [vigSkeletonAnimated]="false" stops the pulse. When it is false the directive adds nothing to the element.
Loading in place
Customizing the directive
- It follows the same tokens as
vig-skeleton:--color-mutedfor the fill and--radius-skeletonfor the corners. - While loading, the element carries
[data-scope="skeleton"][data-part="root"][data-state="loading"]andaria-busy="true"; style that selector to adjust the placeholder. Text bars are background images in the element's content box, so its padding, border and background colour stay;rectandcirclefill the element. - Use it on plain HTML elements. Kit components have their own scope and state on their host, so wrap them, or use their loading input. An inline element such as
<span>has no box while empty: make itinline-block(a flex or grid item already is a block).
Styling hooks
Internal elements carry a stable data-part and the component's data-scope; both are public API, so removing one is a breaking change. Select a part by both, e.g. [data-scope="skeleton"][data-part="bar"] { … }: the pair stays within this component when kit components nest, and also reaches parts in overlay panels, which render outside the host. State is exposed through aria-* and, where listed, a data-state; literal values are checked by the API gate, values computed from the component's state follow its documented types. Other data-* attributes listed below (such as data-opening while an overlay animates) are API too. See Customizing.
Skeleton [data-scope="skeleton"]
| Part | Element | data-state |
|---|---|---|
bar | — |
VigSkeleton [data-scope="skeleton"]
| Part | Element | data-state |
|---|---|---|
root | [vigSkeleton] element while loading ( inert , aria-busy="true" ); nothing while not. | loading |
Accessibility
- Skeletons are hidden from assistive technology by default, so a group of them does not produce a series of empty announcements.
- Give one skeleton per loading region an
ariaLabel, e.g. “Loading profile”: it becomes arole="status"region with that text. - Mark the container that is loading with
aria-busy="true"and set it back tofalseonce the content is in place. - A
vigSkeletonelement isinertwhile loading: stale or empty content is neither read nor focusable, and focusable children leave the tab order instead of being hidden while focusable. It also getsaria-busy="true". It announces nothing by itself, so a page of placeholders is not a series of announcements: give the loading region one status message, as the demo above does. inertalso takes focus away: when loading starts while focus is inside the element, the browser moves it to the page. Move focus to something that stays, such as the loading region itself (tabindex="-1"), before reloading content the user is working in; dev mode warns once when this happens.- An element's own
inert,aria-busyanddata-scope/data-part/data-statevalues come back when loading ends. - In forced-colors mode (Windows High Contrast) the placeholders are drawn in
GrayText, since forced colors drop author backgrounds. - The pulse animation stops when the user prefers reduced motion (
prefers-reduced-motion).
API
Skeleton
vig-skeletonPlaceholder block shown while content loads. Hidden from assistive tech by
default; pass ariaLabel to announce it as a role="status" region.
| Name | Type | Default | Description |
|---|---|---|---|
animated | boolean | true | Pulses while loading; static with reduced motion. |
ariaLabel | string | undefined | undefined | Announces the placeholder (e.g. "Loading profile") as a status region. |
height | string | undefined | undefined | Any CSS length. Text lines are |
lines | number | 1 | Number of text bars ( |
shape | SkeletonShape | 'text' | — |
width | string | undefined | undefined | Any CSS length, e.g. |
VigSkeleton
[vigSkeleton]Turns the element it sits on into its own loading placeholder, so a loading state needs no parallel skeleton markup:
Example :<h2 [vigSkeleton]="loading()">{{ user()?.name }}</h2>
<p [vigSkeleton]="loading()" vigSkeletonLines="3">{{ user()?.bio }}</p>
<img [vigSkeleton]="loading()" vigSkeletonShape="circle" [attr.src]="user()?.avatar" alt="" />While vigSkeleton is true the host keeps its layout box, its content
is hidden (text transparent, child elements visibility: hidden, an
image's picture moved out of its box) and it shows the vig-skeleton
look instead: one bar per line for text, a filled block for rect and
circle. A text host with no content yet (whitespace aside) is
vigSkeletonLines lines tall. The host is inert
(out of the tab order and the accessibility tree, so stale or empty
content is not read; a focused element inside loses focus) and carries
aria-busy="true", data-scope="skeleton", data-part="root" and
data-state="loading". The host's own values of these attributes come
back when loading ends; while false the directive adds nothing.
It announces nothing: give the loading region one announcement, e.g. a
vig-skeleton with an ariaLabel. Use it on plain HTML elements, not on
kit components, whose hosts carry their own scope and state. An inline
element (<span>) has no box while empty: make it inline-block.
root
skeleton
loading
| Name | Type | Default | Description |
|---|---|---|---|
vigSkeleton | boolean | false | Shows the placeholder while |
vigSkeletonAnimated | boolean | true | Pulses while loading; static with reduced motion. |
vigSkeletonHeight | string | undefined | undefined | Height while loading, any CSS length; a |
vigSkeletonLines | number | 1 | Lines an empty |
vigSkeletonShape | SkeletonShape | 'text' |
|
vigSkeletonWidth | string | undefined | undefined | Width while loading, any CSS length (e.g. |