Skeleton swap

A placeholder and the content it stands for in one grid cell, crossfading on aria-busy. No script, but for event.

Anatomy

div.group/skeleton.grid[data-ds-skeleton-swap][aria-busy=true?]
├── div[aria-hidden][data-ds-skeleton-placeholder]   ← the placeholder slot, or ds::skeleton
└── div[data-ds-skeleton-content]                    ← the default slot

Both faces are col-start-1 row-start-1 min-w-0, so the box is the larger of the two from the first paint and nothing below it moves on the swap.

State

One attribute: aria-busy="true" on the root means loading. The faces read it with group-aria-busy/skeleton::

placeholdercontent
busyvisible, opacity 1invisible, opacity 0
not busyinvisible, opacity 0visible, opacity 1

motion-safe:transition-[opacity,visibility] duration-dialog-enter ease-enter: a crossfade, at once under reduced motion. Visibility flips at the end of a fade out, so the hidden face leaves the tab order, the accessibility tree and find-in-page; that is what inert would give, done in CSS so that anything flipping the attribute flips it too.

What writes the attribute:

  • loaded (PHP): false renders it, true does not.
  • Livewire wire:loading.attr="aria-busy": sets "true" for the request and restores the server's value after.
  • An Alpine binding the host writes, x-bind:aria-busy.
  • event: an empty x-data and x-on:{event}.window that removes the attribute. Validated as an event name (no dots, which Alpine reads as modifiers); a bad one throws at render.

Accessibility

Rolenone; aria-busy while loading
Placeholderaria-hidden="true"
Hidden facevisibility: hidden once faded
Keyboardthe content's own
Motionmotion-safe: crossfade

Do not

  • Do not leave it busy forever. No content is an empty state, loaded.
  • Do not size the placeholder far from the content. The cell keeps the larger, so the difference is a gap or a jump.
  • Do not add a second loading state beside it. The attribute is the state.

From the package repo: edit this page on GitHub.

Was this page helpful?