Magnetic Cursor Dock for React

macOS-style dock with magnetic cursor effect. Items scale and lift as cursor approaches.

Component

Installation

 

Usage

Import

Add the MagneticCursorDock import.

import { MagneticCursorDock } from "@/components/magnetic-cursor-dock";

Use

Wrap your dock items.

<MagneticCursorDock>{/* items */}</MagneticCursorDock>;

Guidelines

  • Pass children as dock items. Each child gets the magnetic effect.
  • Use maxDist, scaleFactor, liftAmount to tune the effect.

Props

All props are optional unless marked required. Use these to customize every aspect of the component.

PropTypeDefaultDescription
classNamestring-Additional CSS classes for the dock container.
dockClassNamestring-Additional classes for the dock (merged with className).
maxDistnumber90Max distance (px) for magnetic effect.
scaleFactornumber1.2Scale factor when cursor is near.
liftAmountnumber8Lift amount (px) when cursor is near.

Accessibility

  • The dock is a decorative wrapper of plain divs with no roles, labels, or focusable elements of its own, so any interactivity must come from the children you pass in.
  • The magnetic effect is driven only by mousemove and mouseleave, so it is mouse-only and never activates for keyboard or touch users; ensure the children remain operable and visible without the effect.
  • There is no focus management or visible focus styling on the dock, so add accessible names and focus-visible styles to interactive children yourself.
  • It does not check prefers-reduced-motion, so the scale and lift animation should be guarded or disabled for users who request reduced motion.

Performance

  • It animates only transform properties (scale and translateY) plus z-index via framer-motion motion values, which are compositor-friendly and avoid layout or paint thrashing.
  • Each item runs its own continuous requestAnimationFrame loop that reads getBoundingClientRect every frame, so a dock with many items does proportionally more measurement work each frame.
  • The rAF loop cancels its initial handle on unmount and the mousemove and mouseleave listeners are removed on cleanup, avoiding leaks.
  • There is no will-change hint, IntersectionObserver visibility gating, or reduced-motion gating, so the rAF loop keeps running even when the dock is off-screen or idle.

Examples

Basic

Basic dock with icon items.

import { MagneticCursorDock } from "@/components/magnetic-cursor-dock";
import { Home, Search, Mail } from "lucide-react";

<MagneticCursorDock className="h-24">
  <div className="flex size-12 items-center justify-center rounded-xl bg-zinc-800">
    <Home className="size-6 text-white" />
  </div>
  <div className="flex size-12 items-center justify-center rounded-xl bg-zinc-800">
    <Search className="size-6 text-white" />
  </div>
  <div className="flex size-12 items-center justify-center rounded-xl bg-zinc-800">
    <Mail className="size-6 text-white" />
  </div>
</MagneticCursorDock>;

Last updated on Jun 19

Made with ❤️ by Pulkit &

© 2026 Pulkit. All rights reserved

Last updated: