docs: note that transitions bypass CSS prefers-reduced-motion

Svelte 5 transitions are driven by the Web Animations API, so a global
`@media (prefers-reduced-motion: reduce)` rule that zeroes transition-duration
and animation-duration has no effect on them -- a reader who reaches for the
usual CSS reset gets no warning that it does nothing here.

`prefersReducedMotion` already covers this and is documented on the
svelte/motion page, but nothing on the transition page points to it. This adds
a short Accessibility section that does, reusing the example from the
svelte/motion docs so the two pages stay consistent.
pull/18597/head
Rudevin Cosejo 1 week ago
parent 44a7813730
commit 9983e8e163

@ -41,6 +41,27 @@ Transitions are local by default. Local transitions only play when the block the
A selection of built-in transitions can be imported from the [`svelte/transition`](svelte-transition) module.
## Accessibility
Transitions are driven by the [Web Animations API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Animations_API) rather than by CSS. A global `@media (prefers-reduced-motion: reduce)` rule that zeroes `transition-duration` and `animation-duration` therefore does not reach them, and someone who has asked their operating system for less motion will still see the full animation.
Use [`prefersReducedMotion`](svelte-motion#prefersReducedMotion) to honour the preference:
```svelte
<script>
import { prefersReducedMotion } from 'svelte/motion';
import { fly } from 'svelte/transition';
let visible = $state(false);
</script>
{#if visible}
<p transition:fly={{ y: prefersReducedMotion.current ? 0 : 200 }}>
flies in, unless the user prefers reduced motion
</p>
{/if}
```
## Transition parameters
Transitions can have parameters.

Loading…
Cancel
Save