Skip to content

Signature Pad

Draw a signature with mouse, pen or finger on a canvas with pressure aware strokes, undo and clear, a typed name fallback and PNG export for forms.

src/registry/ui/signature-pad.tsx/r/signature-pad.json

Installation

bash
npx shadcn@latest add @minidev/signature-pad

MiniDev UI is in the shadcn registry directory, so the short form works with no setup. Older CLI versions can use the full URL: npx shadcn@latest add https://ui.minidev.pro/r/signature-pad.json

Usage

tsx
import { SignaturePad } from "@/components/ui/signature-pad"

export function Example() {
  return (
    <SignaturePad />
  )
}

API reference

SignaturePad props
PropTypeDefault
onChangeCalled with a PNG data URL after each stroke or typed change, or null when empty.(dataUrl: string | null) => void-
labelVisible label; also names the canvas and the typed input.string"Signature"
heightCanvas height in px.number180
classNamestring-

When to use

Use it to sign off a contract, a delivery or an approval, where you need an image of the signature rather than a checkbox. Both modes report through one onChange: a drawn signature or the typed name rendered in a script face, as a transparent PNG data URL, or null when empty. Store the data URL or upload it as an image. There is no value prop, so it always starts empty. For a plain "I agree" use Checkbox; for an uploaded image use ImageUpload.

Keyboard interactions

Keyboard interactions
KeyAction
TabMoves to "Type instead", then Undo and Clear. Drawing needs a pointer.
EnterorSpaceOn "Type instead", switches to a text field where the name can be typed.

Accessibility

  • The canvas is role="img", named by the visible label and described by a hidden hint: "Draw your signature with a mouse, pen or finger, or choose Type instead."
  • Keyboard users sign through the Type mode input, which is named by the same label.
  • Undo and Clear are disabled while the pad is empty.

Frequently asked questions

How do I save the signature?

onChange gives a transparent PNG data URL after each stroke, or null when the pad is empty. Upload it or store it as an image. In Type mode the typed name is drawn in a script font to a PNG of the same kind.

Can I load a saved signature or clear it from my code?

No. There is no value prop or ref: the pad always starts empty and is cleared with its own Clear button. To reset it from outside, change its key so React mounts a fresh one.

Why are the strokes white in dark mode?

Strokes use the canvas text colour, text-fg, so in dark mode the PNG has light strokes on a transparent background and can vanish on a white PDF. Change the canvas's text-fg class in your copy if the image must always be dark.

Dependencies

npm

lucide-reacttype

Built from

Examples

Label and height

label names the field for screen readers and height sets the canvas in pixels.

Submit when signed

onChange gives a PNG data URL after each stroke and null after Clear, so you can gate the submit button on it.

In a dialog

The canvas measures itself on mount, so it works inside a Dialog that opens later.

All form components