Signature Pad
ProA page to sign on with a mouse, a finger or a stylus. It keeps each pen stroke as a smooth SVG path, in writing order, so a Signature can play the hand back and a form can submit it.
Installation#
Usage#
The preview is yours to explore. Its code comes with a Pro license, paid once and used in every project.
Have a license? Unlock it here
Anatomy#
import {
SignaturePad,
SignaturePadActions,
SignaturePadUndo,
SignaturePadClear,
} from "@/components/ui/signature-pad"
<SignaturePad>
<SignaturePadActions>
<SignaturePadUndo />
<SignaturePadClear />
</SignaturePadActions>
</SignaturePad>Play it back#
The value is one SVG path per stroke, in the order the hand wrote them, which is exactly what a Signature takes as its children. signatureViewBox(strokes) gives it the box around the ink, so it takes its width from the first paint. The Signature page has the full playground, with every speed and size.
States#
Inside a Field, the pad takes the field's label and hint as its name and description, and its hasError and disabled cascade in, the same as an Input. An error paints the frame; a disabled pad keeps its signature on show but no longer takes the pen or offers Undo and Clear. Both props can also be set on the pad itself. Focus works like any field's: the first stroke focuses the pad, and it stays lit through every lift of the pen and every Undo until you click away, so a signature of five strokes does not blink five times. While it has focus, Ctrl / ⌘ + Z takes back the last stroke.
Without actions#
Undo and Clear are parts, not props: leave SignaturePadActions out and the pad is only a page, for an initial box or a flow that clears it some other way. With them in, they stay hidden until there is a stroke to take back. placeholder replaces the line under the empty page.
In a form#
With a name, the pad submits the drawing as a standalone SVG document, its ink in currentColor: store it, email it, or render it back. Sign, then submit, to see exactly what the form receives. signatureToSvg(strokes) builds the same document from a controlled value.
API reference#
SignaturePad
A <div role="group" tabIndex={-1}> framing the page, 160px tall (an h-* class sets another height); the pen focuses it and the tab stops are Undo and Clear. Forwards all native <div> props, and every part accepts className, merged last.
| Prop | Type | Default | Description |
|---|---|---|---|
| value | string[] | - | The strokes, one SVG path per pen stroke in writing order (controlled). |
| defaultValue | string[] | [] | The strokes to start from (uncontrolled). |
| onValueChange | (strokes: string[]) => void | - | Called when a stroke lands, and on undo and clear, with every stroke so far. |
| name | string | - | Submits the drawing under this name as a standalone SVG document (see signatureToSvg). |
| placeholder | React.ReactNode | "Sign here" | The text on the baseline while the page is empty. |
| hasError | boolean | false | Paints the destructive frame. Falls back to the enclosing Field's error state. |
| disabled | boolean | false | Stops the pen and dims the pad. Falls back to the enclosing Field's disabled state. |
| Data attribute | Description |
|---|---|
| data-empty | Present while there are no strokes and the pen is up. |
| data-drawing | Present while a stroke is being written. |
| data-disabled | Present when the pad is disabled. |
SignaturePadActions
The top-right corner holding Undo and Clear, hidden while the pad is empty. Forwards all native <div> props.
SignaturePadUndo
A ghost sm Button that takes back the last stroke (also Cmd/Ctrl+Z while the pad has focus); disabled while the pad is empty. Forwards every Button prop.
| Prop | Type | Default | Description |
|---|---|---|---|
| children | React.ReactNode | "Undo" | The label. |
| onClick | React.MouseEventHandler<HTMLButtonElement> | - | Runs before the undo; call event.preventDefault() to cancel it. |
SignaturePadClear
A ghost sm Button that wipes the page; disabled while the pad is empty. Forwards every Button prop.
| Prop | Type | Default | Description |
|---|---|---|---|
| children | React.ReactNode | "Clear" | The label. |
| onClick | React.MouseEventHandler<HTMLButtonElement> | - | Runs before the clear; call event.preventDefault() to cancel it. |
signatureViewBox
A function returning the box around the ink, padded, as a viewBox string. Pass it to a Signature to reserve its width from the first paint.
| Prop | Type | Default | Description |
|---|---|---|---|
| strokes* | string[] | - | The pad's value. |
| padding | number | 4 | Space added around the ink, in pad pixels. |
signatureToSvg
A function returning the drawing as a standalone SVG document with currentColor ink: the value the pad submits under name. Returns "" for no strokes.
| Prop | Type | Default | Description |
|---|---|---|---|
| strokes* | string[] | - | The pad's value. |