Animate toggles
Animate toggles
Section titled “Animate toggles”data-automagica11y-animate is now part of the core toggle lifecycle. Any trigger can opt in and automagicA11y will postpone the close transition until CSS transitions and animations finish. No registration step is required—the listener is installed automatically when patterns hydrate.
<button data-automagica11y-toggle="#sheet" data-automagica11y-animate="target" data-automagica11y-target-class-open="sheet--open"> Toggle sheet</button><section id="sheet" hidden class="sheet"> <p>Exit animations finish before the panel hides.</p></section>Pair the attribute with your closing classes so the surface stays visible while animations run. automagicA11y temporarily removes hidden, applies the closing classes, and then hides the target once motion completes.
Opt-in values
Section titled “Opt-in values”| Value | Watched element | Notes |
|---|---|---|
(empty) or target | Target surface | Default. The target stays visible while the closing animation plays. |
trigger | Trigger element | Watch the trigger when it owns the animation (glowing pills, scale-down buttons). |
| CSS selector | Resolved element | Observe any element in the document (overlays, wrappers). The target still receives open/close classes unless you override them. |
When prefers-reduced-motion: reduce is active or the watched element reports zero-duration animations, animate falls back to immediate close so assistive tech never waits on visuals.
Lifecycle
Section titled “Lifecycle”- Triggers dispatch
automagica11y:togglewithexpanded: false. - Animate intercepts the close, applies closing classes, and sets
--automagica11y-animating="closing"on the watched element. - The system listens for
transitionend/animationend,Element.getAnimations(), and a computed timeout fallback. - After animations finish, it hides the target, dispatches
automagica11y:animation-done, and replaysautomagica11y:togglewith__automagica11yAnimateProcessed: trueso core toggle handlers complete cleanup.
Listen for automagica11y:animation-done when you need to chain additional teardown (DOM recycling, analytics, focus handoffs).
Compatibility
Section titled “Compatibility”Animate registers itself automatically for the current document. If you are hydrating toggles inside an iframe or shadow root, call initAnimateLifecycle() with that document to wire up the listener manually.
Coverage plan
Section titled “Coverage plan”- Publish a playground demonstrating trigger-, target-, and selector-based animations.
- Document how animate coordinates with the focus helpers so focus waits until the panel is hidden.
- Provide troubleshooting tips for common configuration mistakes (missing transitions, conflicting preventDefault calls).
Progress rolls up to the Core modules plan.