Interactive Hover Button
A React pill button with an interactive hover effect: a small dot grows to fill the button while the label slides away and an arrow with a new label slides in. Built on the DuskUI Button with Tailwind CSS, it animates only transform and opacity, and keyboard focus triggers the same state as hover.
- Built on DuskUI Button
- Transform & opacity only
- Keyboard focus state
- Width-stable
- prefers-reduced-motion
import { InteractiveHoverButton } from "@/components/dusk/interactive-hover-button/interactive-hover-button";
export default function InteractiveHoverButtonDemo() {
return (
<>
<InteractiveHoverButton size="lg">Get started</InteractiveHoverButton>
<InteractiveHoverButton size="lg" hoverLabel="Let's talk">
Contact sales
</InteractiveHoverButton>
</>
);
}Installation
$ npx shadcn@latest add https://duskui.com/r/interactive-hover-button.json1. Install the dependencies.
npm install lucide-react2. Copy the source into
components/dusk/interactive-hover-button/interactive-hover-button.tsx.interactive-hover-button.tsx "use client"; import * as React from "react"; import { ArrowRight } from "lucide-react"; import { Button, type ButtonProps } from "@/components/ui/button"; import { cn } from "@/lib/utils"; export interface InteractiveHoverButtonProps extends Omit<ButtonProps, "variant" | "asChild"> { /** Any CSS color for the dot and the fill. Defaults to the theme primary. */ color?: string; /** Text color on top of the fill. Defaults to the primary foreground. */ fillForeground?: string; /** Label shown in the hover state. Defaults to `children`. */ hoverLabel?: React.ReactNode; /** Icon that slides in with the hover label. */ icon?: React.ReactNode; } const DOT = 8; /** Pill button whose dot grows to fill it on hover while an arrow and label slide in. */ export function InteractiveHoverButton({ color = "var(--color-primary)", fillForeground = "var(--color-primary-foreground)", hoverLabel, icon = <ArrowRight />, className, style, children, ...props }: InteractiveHoverButtonProps) { const dot = React.useRef<HTMLSpanElement>(null); // Scale the dot just enough for its circle to cover the whole button. React.useEffect(() => { const el = dot.current; const button = el?.closest<HTMLElement>("[data-slot=button]"); if (!el || !button) return; const fit = () => { const cx = el.offsetLeft + DOT / 2; const reach = Math.hypot(Math.max(cx, button.offsetWidth - cx), button.offsetHeight / 2); button.style.setProperty("--ihb-scale", String(Math.ceil((reach * 2) / DOT) + 1)); }; fit(); const observer = new ResizeObserver(fit); observer.observe(button); return () => observer.disconnect(); }, []); const motionSafe = "transition-[translate,opacity] duration-250 ease-out motion-reduce:transition-opacity"; return ( <Button variant="outline" className={cn( "group/ihb isolate overflow-hidden rounded-full pr-5 pl-4 [--ihb-scale:48]", "dark:bg-transparent dark:hover:bg-transparent hover:bg-transparent", className )} style={{ "--ihb": color, "--ihb-fg": fillForeground, ...style } as React.CSSProperties} {...props} > <span ref={dot} aria-hidden data-slot="ihb-dot" className={cn( "pointer-events-none absolute top-1/2 left-4 -z-10 -translate-y-1/2 rounded-full bg-(--ihb)", "transition-[scale] duration-300 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none", "group-hover/ihb:scale-(--ihb-scale) group-focus-visible/ihb:scale-(--ihb-scale)" )} style={{ width: DOT, height: DOT }} /> {/* Both labels share one grid cell, so the width fits the wider one and never shifts. */} <span className="relative grid items-center"> <span className={cn( "col-start-1 row-start-1 inline-flex items-center gap-2 pl-4", "group-hover/ihb:opacity-0 group-focus-visible/ihb:opacity-0", "motion-safe:group-hover/ihb:translate-x-10 motion-safe:group-focus-visible/ihb:translate-x-10", motionSafe )} > {children} </span> <span aria-hidden className={cn( "col-start-1 row-start-1 inline-flex items-center justify-center gap-2 text-(--ihb-fg) opacity-0", "group-hover/ihb:opacity-100 group-focus-visible/ihb:opacity-100", "motion-safe:-translate-x-10 motion-safe:group-hover/ihb:translate-x-0 motion-safe:group-focus-visible/ihb:translate-x-0", motionSafe )} > {hoverLabel ?? children} {icon} </span> </span> </Button> ); }
Builds on the DuskUI Button; the CLI installs it automatically. Installing by hand? Add components/ui/button.tsx from the Button page first.
Usage
import { InteractiveHoverButton } from "@/components/dusk/interactive-hover-button/interactive-hover-button"
export function Cta() {
return <InteractiveHoverButton size="lg">Get started</InteractiveHoverButton>
}Examples
Color, icon & hover label
color sets the dot and fill, fillForeground the text on top of it. icon replaces the arrow and hoverLabel shows different text on hover.
import { Download, Send } from "lucide-react";
import { InteractiveHoverButton } from "@/components/dusk/interactive-hover-button/interactive-hover-button";
export default function InteractiveHoverButtonCustomDemo() {
return (
<>
<InteractiveHoverButton color="#a78bfa" fillForeground="#0b0618" icon={<Download />} hoverLabel="v2.4.0">
Download
</InteractiveHoverButton>
<InteractiveHoverButton color="#f472b6" fillForeground="#1a0510" icon={<Send />}>
Send invite
</InteractiveHoverButton>
<InteractiveHoverButton color="#facc15" fillForeground="#1a1400" size="sm">
Small
</InteractiveHoverButton>
</>
);
}Loading
loading comes from the base Button: the content crossfades to a spinner without changing the width, and the button stays focusable.
"use client";
import * as React from "react";
import { InteractiveHoverButton } from "@/components/dusk/interactive-hover-button/interactive-hover-button";
export default function InteractiveHoverButtonLoadingDemo() {
const [loading, setLoading] = React.useState(false);
const timer = React.useRef<ReturnType<typeof setTimeout>>(undefined);
React.useEffect(() => () => clearTimeout(timer.current), []);
const subscribe = () => {
setLoading(true);
clearTimeout(timer.current);
timer.current = setTimeout(() => setLoading(false), 2000);
};
return (
<InteractiveHoverButton size="lg" loading={loading} onClick={subscribe} hoverLabel="It's free">
Subscribe
</InteractiveHoverButton>
);
}API Reference
Also accepts every DuskUI Button prop (size, loading, loadingText) except variant and asChild.
| Prop | Type | Default | Description |
|---|---|---|---|
| color | string | var(--color-primary) | Any CSS color for the dot and the fill. |
| fillForeground | string | var(--color-primary-foreground) | Text color on top of the fill. |
| hoverLabel | ReactNode | children | Label shown in the hover state. |
| icon | ReactNode | <ArrowRight /> | Icon that slides in with the hover label. |
| className | string | — | Merged with tailwind-merge, so overrides win. |
Accessibility
- Renders a native <button>; keyboard focus (focus-visible) shows the same filled state as hover, plus the standard focus ring.
- The hover label is aria-hidden, so screen readers announce the main label once.
- Both labels share one grid cell, so the button is always as wide as the wider label and never shifts layout.
- With prefers-reduced-motion nothing slides: the labels crossfade and the fill appears instantly.
- Only transform and opacity animate, so the effect stays smooth and never triggers layout.