Gravity Letters
Text whose letters detach and fall under gravity, pile up at the bottom, and can re-form on demand.
Installation
npx smoothui-cli add gravity-lettersFeatures
- Each letter's rest position is measured once with
getBoundingClientRectand never recomputed during animation, only on resize - A single
requestAnimationFrameloop integrates position, velocity, and angular velocity per letter and writestransformdirectly to refs — no React state per frame - Letters collide with the container floor and walls only, with configurable restitution (
bounce) andfriction - Staggered detachment (
stagger) and a random horizontalspreadimpulse give the fall a natural, scattered feel - Four trigger modes:
hover,click,inView(falls once when scrolled into view), andmanual(fully controlled viacollapsed/onCollapsedChange) - Re-forming springs every letter back to its measured origin
Accessibility
ARIA Attributes
| Attribute | Element | Purpose |
|---|---|---|
aria-hidden="true" | Measurement layer and animated letter layer | Hides the decorative, per-letter spans from assistive technologies |
role="button" | Container (trigger="click" only) | Identifies the container as activatable when click-to-topple is enabled |
aria-pressed | Container (trigger="click" only) | Reflects whether the text is currently collapsed (fallen) |
Screen Reader
- The full string is always present as real, visually-hidden (
sr-only) text, independent of animation state, so screen readers always read the intended sentence. - The animated letter spans are
aria-hiddenand never become the accessible content. - For
trigger="hover"andtrigger="click", the container is keyboard-focusable (tabIndex={0}); focusing it triggers the same effect as hovering, andclickalso responds to Enter/Space.
Reduced Motion
This component respects prefers-reduced-motion via useReducedMotion from Motion. When reduced motion is preferred, letters never fall — the component renders the plain, fully readable text with no measurement layer, no physics loop, and no interaction handlers.
Props
Created by
Powered by
© 2026 SmoothUI. Built by Eduardo Calvo.