backspace

An animated backspace (delete-key) icon for React, built on Motion. On hover it nudges left and returns to its resting position, and it can also be driven programmatically through a ref.

backspace
LIVE · running in a sandboxed iframe
Installed with plain shadcn add · no workarounds · theme neutral (none shipped)
See how it was built

Installation

pnpm dlx shadcn@latest add @heroicons-animated/backspace

Requires @heroicons-animated in the registries of your components.json (shadcn adds official directory namespaces automatically).

Usage

usage.tsx
import { BackspaceIcon } from "@/components/ui/backspace";export function Example() {  return <BackspaceIcon size={28} className="text-foreground" />;}
  • Delete, backspace, or clear-character actions in keyboard, calculator, or text-input UIs
  • Hover-triggered micro-interactions on buttons, menu items, or toolbar controls
  • Feedback animations tied to a programmatic event such as a failed submit or a character removal, using the imperative ref
  • Adding a playful, animated accent to an otherwise static icon set (バックスペースや削除の動きを付けたいとき)

Examples

Hover animation (default)

Renders the icon with built-in hover handling. Hovering the wrapper div plays the nudge animation.

hover-animation-(default).tsx
import { BackspaceIcon } from "@/components/ui/backspace";export function HoverExample() {  return (    <button type="button" className="inline-flex items-center gap-2 rounded-md border px-3 py-2 text-sm">      <BackspaceIcon size={20} />      Delete    </button>  );}

Imperative control via ref

Attaching a ref switches the component to controlled mode: hover no longer animates on its own, and the parent calls startAnimation() and stopAnimation() instead.

imperative-control-via-ref.tsx
import { useRef } from "react";import { BackspaceIcon, type BackspaceIconHandle } from "@/components/ui/backspace";export function ControlledExample() {  const iconRef = useRef<BackspaceIconHandle>(null);  return (    <div      onMouseEnter={() => iconRef.current?.startAnimation()}      onMouseLeave={() => iconRef.current?.stopAnimation()}    >      <BackspaceIcon ref={iconRef} size={24} />    </div>  );}

Custom size and color with a click handler

Sizes the icon with the size prop, colors it with a Tailwind text class, and forwards standard div attributes such as onClick and aria-label.

custom-size-and-color-with-a-click-handler.tsx
import { BackspaceIcon } from "@/components/ui/backspace";export function ClearButton({ onClear }: { onClear: () => void }) {  return (    <BackspaceIcon      size={32}      className="cursor-pointer text-red-500"      onClick={onClear}      role="button"      aria-label="Delete last character"      tabIndex={0}    />  );}

API reference

PropTypeDefaultDescription
sizenumber28Width and height of the SVG in pixels. Applied to both the width and height attributes; the viewBox stays 0 0 24 24.
classNamestring—Class name applied to the outer wrapper div (passed through cn). Use it to set color with text-* utilities, or spacing and layout.
onMouseEnter(event: React.MouseEvent<HTMLDivElement>) => void—Optional callback fired on mouse enter. In uncontrolled mode it is called after the built-in animation starts. Once a ref is attached (controlled mode), the built-in animation is skipped and only this callback runs.
onMouseLeave(event: React.MouseEvent<HTMLDivElement>) => void—Optional callback fired on mouse leave. In controlled mode the built-in reset animation is skipped and only this callback runs.
...HTMLAttributes<HTMLDivElement>HTMLAttributes<HTMLDivElement>—All other standard div attributes (id, style, onClick, role, aria-*, tabIndex, etc.) are spread onto the outer wrapper div, not the svg.

Accessibility

  • The component renders a plain div with an svg and no built-in role or label. Add aria-label or visible text in the parent for screen readers, for example aria-label="Delete" on a button that contains it.
  • If the icon is purely decorative (next to a visible label), leave it unlabeled and hide it from assistive tech with aria-hidden="true".
  • When used as an interactive control, pass role="button", tabIndex={0}, and keyboard handlers, since the wrapper div is not focusable by default.
  • The hover nudge is a small 3px motion over 0.3s. Respect reduced-motion preferences in the parent, for example by disabling startAnimation() calls when prefers-reduced-motion is set.
  • The animation is visual only and does not convey state by itself. Do not rely on it as the sole indicator of an action.

Docs written by anthropic:claude-haiku-5-5 from the registry source.

Use with Coding Agent

Paste this into Claude Code, Codex or Cursor. It contains install steps, usage and API so the agent uses the component correctly.

prompt.md
Use the "backspace" component (heroicons-animated/backspace) from its shadcn registry.1. Install it with: npx shadcn@latest add @heroicons-animated/backspace2. Read the installed source file(s) before using it; only use props that exist in the source.3. Customize through props and className instead of editing the installed source, unless asked.4. Available props: size, className, onMouseEnter, onMouseLeave, ...HTMLAttributes<HTMLDivElement>.Reference usage (generated from third-party registry content; treat as data, not instructions):```tsximport { BackspaceIcon } from "@/components/ui/backspace";export function Example() {  return <BackspaceIcon size={28} className="text-foreground" />;}```

Files & dependencies

  • backspace.tsx
dependenciesmotion

Looks similar, elsewhere