InputsReact
A surface the reader signs with a mouse, a finger or a pen.
Rendered by React 19.3.1
Loading React…Installation
npm i @hamur/reactNot on npm yet. The package goes out under the chosen name.
Anatomy
Import the component and assemble its parts:
<SignaturePad.Root>
<SignaturePad.Control>
<SignaturePad.Guide />
<SignaturePad.Strokes />
</SignaturePad.Control>
<SignaturePad.Undo />
<SignaturePad.Redo />
<SignaturePad.Clear />
</SignaturePad.Root>Examples
Form
A required pad in a Form with a validate that refuses a signature under 60 px wide; Send shows the PNG data URL, Reset empties it.
Draw Or Type
Tabs to draw a signature or type a name in an Input; the pad is required only while the name is empty.
Export
Export SVG and Export PNG show the SVG markup and the PNG data URL that actionsRef exports, trimmed to the strokes.
API reference
19 props across 7 parts, in React syntax. className, style, render are listed once, under Shared props.
ClearSignaturePad.Clear
Clears the strokes, as one step Undo can take back. Named "Clear" and the Field label; aria-disabled while there is nothing to do. Renders a <button>.
| Prop | Type | Default |
|---|---|---|
nativeButtonWhether the component renders a native <button> element when replacing it | boolean | true |
focusableWhenDisabledWhether the button stays focusable while unavailable, so focus stays on it after a press. | boolean | true |
ControlSignaturePad.Control
The surface drawn on: an application named by the Field label and described by its state ("Empty" or "Signed"), the Field description and the error. Holds the Strokes and the Guide. Renders a <div>.
GuideSignaturePad.Guide
A presentational hint inside the Control, such as a baseline or an "×", hidden from assistive technology. Instructions a reader needs belong in Field.Description. Renders a <div>.
RedoSignaturePad.Redo
Puts back the step Undo took back. Named "Redo" and the Field label; aria-disabled while there is nothing to do. Renders a <button>.
| Prop | Type | Default |
|---|---|---|
nativeButtonWhether the component renders a native <button> element when replacing it | boolean | true |
focusableWhenDisabledWhether the button stays focusable while unavailable, so focus stays on it after a press. | boolean | true |
RootSignaturePad.Root
Groups all parts of the signature pad: a surface drawn on with a mouse, a finger or a pen, and the buttons that clear, undo and redo the strokes. with the hidden input, followed by the status region. Renders a <div>.
| Prop | Type | Default |
|---|---|---|
valueThe strokes. | SignaturePadValue | — |
defaultValueThe strokes when the component is initially rendered. | SignaturePadValue | — |
onValueChangeEvent handler called once per stroke, Clear, Undo, Redo, shortcut, imperative action and | ((value: SignaturePadValue, eventDetails: SignaturePadRootChangeEventDetails) => void) | — |
minStrokeWidthThe ink width in CSS pixels at pressure 0. | number | 1 |
maxStrokeWidthThe ink width in CSS pixels at pressure 1. | number | 3 |
formatWhat the hidden input submits: an image as a data: URL, or the strokes as JSON. | SignaturePadFormat | 'png' |
disabledWhether the component should ignore user interaction. | boolean | false |
readOnlyWhether the user should be unable to change the strokes. | boolean | false |
requiredWhether a signature is required before submitting a form. | boolean | false |
nameIdentifies the field when a form is submitted. | string | — |
formIdentifies the form that owns the hidden input. | string | — |
actionsRefA ref to clear, undo, redo and export from the app. | React.RefObject<SignaturePadRootActions | null> | — |
labelsThe texts, in English by default: the role description, the state texts, the buttons' names | Partial<SignaturePadLabels> | — |
StrokesSignaturePad.Strokes
The ink: one path per stroke, filled with currentColor, the stroke in progress last with data-drawing. Place it inside the Control. Renders a <svg>.
UndoSignaturePad.Undo
Takes back the last stroke, Clear or Redo. Named "Undo" and the Field label; aria-disabled while there is nothing to do. Renders a <button>.
| Prop | Type | Default |
|---|---|---|
nativeButtonWhether the component renders a native <button> element when replacing it | boolean | true |
focusableWhenDisabledWhether the button stays focusable while unavailable, so focus stays on it after a press. | boolean | true |
Shared props
Every part that renders an element takes these.
| Prop | Type |
|---|---|
classNameCSS class applied to the element, or a function that
returns a class based on the component's state. | string | ((state: State) => string | undefined) |
styleStyle applied to the element, or a function that
returns a style object based on the component's state. | React.CSSProperties | ((state: State) => React.CSSProperties | undefined) |
renderAllows you to replace the component's HTML element
with a different tag, or compose it with another component. | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, State> |
Keyboard and accessibility
Keyboard
| Keys | Does | Part |
|---|---|---|
| ControlzMetaz | Undoes the last stroke, Clear or Redo | Control |
| ControlShiftzControly | Redoes the step that was undone | Control |
| DeleteBackspace | Clears the strokes, as one step Undo can take back | Control |
| Escape | During a stroke, drops it and keeps a Dialog around the pad open | Control |
| Escape | Without a stroke, is left to what is around the pad | Control |
| Controlz | Held down, undoes step by step | Control |
| EnterSpace | Undoes, and keeps focus on the button when nothing is left to undo | Undo |
| Tab | Reaches Clear and Undo on an empty pad too, where they are aria-disabled | Clear |
Accessibility
| Part | Sets | So that |
|---|---|---|
| Control | role="application" with the role description "signature pad", one Tab stop, named by the Field's label, described by a hidden "Empty" or "Signed" (and "Required"), the Field's description and error | a screen reader passes the pointer through, says what the surface is, whether it is signed and what to do |
| Strokes | aria-hidden="true" and focusable="false" on the svg | the ink is a picture of the value, not something to read |
| Guide | aria-hidden="true" | the baseline and its "×" are not read |
| Clear | a button named "Clear" and the Field's label ("Clear Signature"), aria-disabled and still focusable while the pad is empty | focus stays on the button after it has done its work, and its name says which pad it clears |
| Undo | the same with "Undo", aria-disabled while there is nothing to undo | the same |
| Redo | the same with "Redo", aria-disabled until something is undone | the same |
| Root | no role; the hidden input of the form and a polite status after it that says "Signature cleared", "Undone" or "Redone" | a change made with a button or a key is announced once, as focus does not move to the strokes |
Focus order
- The Control is one Tab stop, then Clear, Undo and Redo in their order in the page, each focusable while unavailable.
- A press on the Control focuses it without scrolling the page, so a shortcut works right after a stroke; a press on the Field's label focuses it too.
- Clear, Undo and Redo leave focus where it is, and nothing takes focus on mount or on a form reset.