# 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.

- Kind: Component (Forms)
- Docs: https://ui.minidev.pro/docs/signature-pad
- Source (registry JSON with the full file): https://ui.minidev.pro/r/signature-pad.json
- License: MIT. One file, yours to edit after install.

## 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.

## Installation

### shadcn CLI (copies the source into your project)

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

Writes `components/ui/signature-pad.tsx` plus the MiniDev files it is built from (button) and installs its npm dependencies. Older CLI versions: `npx shadcn@latest add https://ui.minidev.pro/r/signature-pad.json`.

### npm package

```bash
npm i minidev-ui-kit lucide-react type
```

Add the tokens to your global stylesheet once:

```css
@import "tailwindcss";
@import "minidev-ui-kit/styles.css";
@source "../node_modules/minidev-ui-kit";
```

Next.js also needs `transpilePackages: ["minidev-ui-kit"]` in next.config.

## Import

After the shadcn install:

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

From the npm package:

```tsx
import { SignaturePad } from "minidev-ui-kit/ui/signature-pad"
```

## Usage

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

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

## Props

| Prop | Type | Default | Required | Description |
| --- | --- | --- | --- | --- |
| `onChange` | `(dataUrl: string \| null) => void` | - | no | Called with a PNG data URL after each stroke or typed change, or null when empty. |
| `label` | `string` | `"Signature"` | no | Visible label; also names the canvas and the typed input. |
| `height` | `number` | `180` | no | Canvas height in px. |
| `className` | `string` | - | no |  |

## Examples

### Label and height

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

```tsx
<SignaturePad label="Signature of Maya Chen" height={120} />
```

### 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.

```tsx
function SubmitDemo() {
  const [signature, setSignature] = React.useState<string | null>(null)
  return (
    <div className="flex w-full max-w-md flex-col gap-3">
      <SignaturePad label="Sign to approve INV-2041" onChange={setSignature} />
      <div className="flex items-center justify-between gap-3">
        <p className="text-xs text-fg-muted">
          {signature ? "Captured as a " + Math.round(signature.length / 1024) + " KB PNG" : "Nothing signed yet"}
        </p>
        <Button size="sm" disabled={!signature}>
          Approve
        </Button>
      </div>
    </div>
  )
}
```

### In a dialog

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

```tsx
<Dialog>
  <DialogTrigger render={<Button variant="outline" />}>Sign agreement</DialogTrigger>
  <DialogContent>
    <DialogHeader>
      <DialogTitle>Sign the Northwind agreement</DialogTitle>
      <DialogDescription>Draw your signature, or choose Type instead to type your name.</DialogDescription>
    </DialogHeader>
    <SignaturePad label="Signature" height={160} className="max-w-none" />
    <DialogFooter>
      <DialogClose render={<Button variant="outline" />}>Cancel</DialogClose>
      <Button>Sign and send</Button>
    </DialogFooter>
  </DialogContent>
</Dialog>
```

## Keyboard interactions

| Key | Action |
| --- | --- |
| `Tab` | Moves to "Type instead", then Undo and Clear. Drawing needs a pointer. |
| `Enter` or `Space` | On "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.

## FAQ

### 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.

## Rules for generating code

- Use semantic tokens only (bg, surface, sunken, border, fg, fg-muted, fg-subtle, ink, accent, success, warning, danger). Never raw hex or palette steps like blue-500.
- Shadows only from the set: shadow-xs, shadow-sm, shadow-raised, shadow-md, shadow-lg, shadow-overlay.
- Numbers use tabular-nums. Dark mode is the `dark` class on <html>; components never branch on theme.

## Dependencies

- npm: `lucide-react`, `type`
- Built from: [button](https://ui.minidev.pro/docs/button/md)

## Related

- [Checkbox](https://ui.minidev.pro/docs/checkbox/md): Shadcn style checkbox on Base UI with an animated check, indeterminate state, invalid and disabled styles, and an enlarged hit area for touch.
- [Image Upload](https://ui.minidev.pro/docs/image-upload/md): A single image picker that starts as a drag and drop zone, then swaps to a large preview with a remove button. Returns an object URL and the File in React.
- [Autocomplete](https://ui.minidev.pro/docs/autocomplete/md): Text input that filters string options as you type, using ARIA combobox and listbox roles. Works controlled or uncontrolled and lists up to eight matches.
- [Calendar Month](https://ui.minidev.pro/docs/calendar-month/md): Month calendar grid with weekday headers and clickable day cells that highlight the selected date. A simple Tailwind base for date views and schedulers.
- [Character Count](https://ui.minidev.pro/docs/character-count/md): Live React character counter that shows the current count against a limit and turns red when it goes over. Announces changes politely to screen readers.
- [Checkbox Group](https://ui.minidev.pro/docs/checkbox-group/md): Vertical wrapper that groups related checkboxes under role group with even spacing. Use it with Checkbox and labels for multi select settings.

---

All 557 components: https://ui.minidev.pro/llms.txt (full text: https://ui.minidev.pro/llms-full.txt).
