Skip to content
Focsd homeFocsd homeFocsd
Forms

Signature pad

A signature drawn with a mouse, finger or pen, or typed as a name instead.

  • Tag: focsd-signature-pad
  • Pattern: Image (role=img) with a typed-name alternative
  • Category: Forms

Example

Accept the agreement Start again
HTML
<form class="stack" id="sign-demo-form">
<focsd-signature-pad
label="Signature"
name="signature"
hint="Draw with a mouse, finger or pen, or choose Type instead."
required></focsd-signature-pad>
<div class="row">
<focsd-button type="submit" variant="action">Accept the agreement</focsd-button>
<focsd-button type="reset">Start again</focsd-button>
</div>
<output id="sign-demo-out" for="sign-demo-form" aria-live="polite"></output>
</form>
<script type="module">
const form = document.getElementById('sign-demo-form');
form.addEventListener('submit', (event) => {
event.preventDefault();
const file = new FormData(form).get('signature');
document.getElementById('sign-demo-out').textContent = file ? 'Signed: ' + file.name + ' (' + file.size + ' bytes)' : 'Please sign first.';
});
</script>

Usage

Import the module once, then use the tag like any HTML element. Every framework below renders the same element; see Frameworks for setup.

<script type="module">
import '@focsd-dev/components/focsd-signature-pad.js';
</script>
<focsd-signature-pad label="Signature" name="signature" hint="Draw with a mouse, finger or pen, or choose Type instead." required></focsd-signature-pad>

API

Attributes

AttributePropertyTypeDefault
namenamestring—
disableddisabledbooleanfalse
requiredrequiredbooleanfalse
readonlyreadOnlybooleanfalse
aria-labelhostAriaLabelstring | nullnull
aria-descriptionhostAriaDescriptionstring | nullnull
aria-labelledbyhostAriaLabelledBystring | nullnull
aria-describedbyhostAriaDescribedBystring | nullnull
label-positionlabelPosition'top' | 'start' | 'end' | undefined—
hinthintstring—
errorerror——
warningwarningstring | undefined—
successsuccessstring | undefined—
error-messageerrorMessagestring | undefined—
warning-messagewarningMessagestring | undefined—
warning-patternwarningPatternstring | undefined—
labellabelstring—
pen-colorpenColorstring—
pen-widthpenWidthnumber2
typedtypedbooleanfalse
typed-nametypedNamestring—

Methods

MethodDescription
describedByIds()IDs to add to the inner control's aria-describedby: the hint, then the shown message.
checkValidity()True when the value is valid; otherwise fires invalid and returns false, like native.
reportValidity()Like checkValidity(), and also shows the browser's validation message when invalid.
setCustomValidity(message)Set (non-empty) or clear (empty string) a custom validation error, like native controls.
setValidityState(flags, message, anchor)For subclasses: set the validity flags and message. anchor is the element the browser points its message at.
validate()Show (or clear) the error from the control's own checks: required, type, pattern, min, max and the like. Uses error-message, else the browser's localized message. An error the author set (a server error, say) is left as it is.
clearValidation()Clear the error and warning that validate() and warning-pattern showed (a form reset does).
emitValue(commit)For subclasses: fire the value events, as a native control does on a user edit: input (bubbles, composed), then with commit also change (bubbles, stays in its tree).
idrefText(ids)For subclasses: the text of the elements an ID reference list names, resolved in the host's tree (ID references cannot cross a shadow root), joined by spaces.
clear()Remove the signature (the drawing and the typed name), from code: no events fire, as for native value writes.
undo()Remove the last stroke, from code (no events).
toDataURL()The signature as a PNG data URL, or an empty string when there is none.
toSVG()The signature as SVG (stroke paths, or the typed name as text), or an empty string when there is none.

Events

EventDescription
inputFired at the end of each stroke and on each typed character.
changeFired when the pointer or focus leaves after drawing, when the typed name is committed, and after Clear, Undo or a mode switch.

CSS parts

Style the inside of the component with ::part(), for example focsd-signature-pad::part(group).

PartDescription
groupThe group around the pad and its buttons, named by the label.
labelThe label element.
layoutThe wrapper that places the label beside or above the body.
bodyThe pad, its buttons, the hint and message.
typed-fieldThe text field for the typed name (typed mode only).
surfaceThe box around the canvas and its baseline.
canvasThe drawing (`role=img`).
baselineThe line to sign on.
actionsThe row of buttons.
modeThe "Type instead" / "Draw instead" button.
undoThe Undo button (drawing mode only).
clearThe Clear button.
statusThe visually hidden region that announces "Signature added" or "Signature cleared".
hintThe author's hint.
messageThe shown error, warning or success message (also `error`, `warning` or `success`).
message-iconThe message's icon.
announcerThe visually hidden region for messages.

Accessibility

  • Drawing is not the only way in. "Type instead" turns the pad into a text field labeled "Type your name for Signature", and the name is drawn as a typed signature. People who cannot draw, or use a keyboard or a screen reader, sign this way.
  • The group is named by the label and described by the hint and any message (read once when focus enters). The canvas is an image named "Signature, signed" or "Signature, empty". A polite status says "Signature added" or "Signature cleared" after each change. When required and empty, the message is "Add your signature."
  • It uses pointer events, so mouse, touch and pen all work, and it keeps touch-action: none on the canvas only, so the page still scrolls around it.
  • required with an empty pad gives the "Required" message, anchored on the mode button (or on the typed field in typed mode).
  • The form receives a PNG file named signature.png, plus signature-typed set to true when the name was typed. It is empty, not a blank image, until someone signs.
  • The ink is black unless you set pen-color, so a signature stays readable on paper in a dark theme. In forced colors the canvas draws in the system text color.
  • Agents never fill this field: WebMCP leaves the signature pad out of its tools, so nothing signs on a person's behalf.

Keyboard

KeyAction
TabMove through Type instead (or Draw instead), Undo and Clear
Enter / SpacePress the focused button
Type your nameIn typed mode, an ordinary text field