Magnetic Button
betaA button that drifts toward the pointer — optionally with its label leaning further — and springs back when it leaves.
- Forms
- 1 file
- No extra npm packages
- Accessibility notes
Loading the example…
pnpm dlx @dowel-ui/cli add magnetic-buttonNo npm packages are needed beyond what Dowel already requires.
import { MagneticButton } from "@/components/ui/magnetic-button";Default
Gallery
Layered
With Radius
As Link
<MagneticButton>
| Prop | Type | Default |
|---|---|---|
contentStrengthThe content's total pull, for a layered effect. Set it above | number | — |
radiusHow far beyond its edges, in pixels, the button starts to feel the pointer. The pull fades to nothing at this distance. 0 (the default) keeps the effect within the button's own bounds. | number | 0 |
strengthHow far the button drifts toward the pointer, as a fraction of the pointer's distance from its centre. 0 turns the effect off. | number | 0.35 |
The drift is decoration on an ordinary Button: name, role and keyboard behaviour are unchanged. It never runs for touch or coarse pointers, or under prefers-reduced-motion, and a disabled or loading button stays put. The `radius` option listens on the window rather than widening the hit area, so it never steals clicks from neighbouring controls.
8/8
checks passed
- Tested — passes
- axe assertion — passes
- Keyboard tested — does not apply
- Storybook examples — passes
- Accessibility documented — passes
- Semantic tokens only — passes
- Motion from tokens — passes
- className merged — passes
- Visible focus — does not apply
- No fixed widths — passes