v22.18.0 release notes

SignaturePad

SignaturePad captures a handwritten signature with a mouse, a pen or a finger, with smooth lines that follow the speed and the pressure, undo and redo, and a typed alternative. Its value is a PNG, an SVG or the strokes, in every kind of Angular form.

View as .md
import { SignaturePad } from '@exhaustive-ui/core/signaturepad';

SignaturePad is bound with ngModel. Draw with the mouse, a pen or a finger: the line gets thinner when the pointer moves faster, and follows the pressure of a pen. The value is a PNG data URL by default, and null while the pad is empty. The canvas is drawn at the pixel density of the screen, and the drawing is kept when the pad is resized.

Not signed yet

penColor sets the color of the new strokes; without it, the pen takes the color of the theme, light in the dark color scheme, while the exported images use the dark export pen color of the theme. minWidth and maxWidth bound the width of the line, in CSS pixels, and velocityFilterWeight sets how quickly the width follows the speed. backgroundColor paints the pad, and the exported images, which are transparent otherwise.

Pen colorBlackBlueGreen
Width 1 to 4 px

The toolbar under the pad undoes the last stroke, redoes it and clears the pad; Ctrl+Z, Ctrl+Y and Ctrl+Shift+Z (⌘ on macOS) do the same after drawing. Clearing can be undone too. Set showToolbar to false to build your own controls with the undo, redo and clear methods, and the canUndo, canRedo and isEmpty signals. The toolbar is laid out from right to left in right-to-left pages.

toDataURL gives the signature as an image data URL, toBlob as a Blob to upload or download, and toSVG as an SVG document whose strokes keep their varying width. The images have the size of the pad the signature was drawn on, at the pixel density of the screen or the given scale. toPoints gives the strokes with the time and the pressure of every point: store them, and give them back to fromPoints to draw the signature again, still editable.

Drawing needs a pointer, so the signature can also be typed: the Type tab shows a text field, and the name is drawn on the pad in a handwriting font, then exported like a drawn signature, as a PNG, an SVG text or points. mode is a model, 'draw' or 'type', and the value follows the active mode; the drawing is kept while the user types, and the other way round. typedFont sets the font family, a stack of handwriting fonts shipped with the common systems by default, and allowTyping set to false removes the tabs.

Mode: type. No signature yet.

The value is null while the pad is empty, so required means "signed", as on the other fields. Resetting the form clears the pad.

SignaturePad can also be used with reactive forms, through formControlName. Here the value is the strokes, with valueFormat set to 'points': setting the control to stored points draws the signature again.

SignaturePad can also be used with Angular Signal Forms. The [formField] directive binds the component to a field holding the signature, null while the pad is empty, so Signal Forms' required works as is. The invalid style waits until the user has drawn or the form is submitted.

A readonly pad shows the signature, drawn or typed, without the tabs and the toolbar. When disabled is present, nothing can be drawn, typed or switched. The invalid state is applied with the invalid property to indicate failed validation.

Readonly
Disabled
Invalid

Screen Reader

Drawing needs a pointer, so the signature can also be typed: the Draw and Type tabs follow the tabs pattern, and the Type tab shows a labelled text field, whose name is drawn in a handwriting font and exported like a drawn signature. Keep allowTyping on when a signature is required, so that keyboard and screen reader users can sign too.

The component is a group named "Signature", or by ariaLabel or ariaLabelledBy. The pad is an image whose name tells its status, "Signature pad, empty", "Signature pad, signed" or "Signature pad, typed signature: Ada Lovelace", and which is described by instructions. A polite live region announces "Signature added", "Signature cleared", "Last stroke undone" and "Stroke restored". The undo and redo buttons have a name and a tooltip, and aria-keyshortcuts; buttons that can not act yet stay focusable with aria-disabled. aria-invalid follows the invalid state and aria-required is set on the typed field. Every text can be translated with labels.

<label id="signature-label">Signature of the buyer</label>
<p-signature-pad ariaLabelledBy="signature-label" [labels]="{ pad: 'Zone de signature', empty: 'vide', signed: 'signée', draw: 'Dessiner', type: 'Saisir' }" />

Tabs Keyboard Support

KeyFunction
tabMoves focus to the active tab, then to the typed field in the Type tab, then to the toolbar.
left arrow / right arrowSelects the previous or next tab, reversed in right-to-left layouts.
home / endSelects the first or the last tab.

Toolbar Keyboard Support

KeyFunction
tabMoves focus into the toolbar, on the last button used, and out of it.
left arrow / right arrowMoves focus to the previous or next button, reversed in right-to-left layouts.
home / endMoves focus to the first or the last button.
enter / spaceRuns the focused button.
ctrl + zUndoes the last stroke, when the focus is in the component, outside the typed field.
ctrl + y / ctrl + shift + zRedoes the last undone stroke. On macOS, ⌘ works like ctrl.