Signature
A canvas-based signature pad: pointer events cover mouse/pen/touch, DPR-aware crisp rendering, stroke color follows theme tokens (auto-flips in dark), strokes survive container resizes, and value (PNG dataURL) is two-way bindable.
Basic Usage
Basic signature
Press and drag on the pad to sign; oas-change fires when the stroke ends (pointer up).
value is a PNG dataURL of the signature: it is written to the attribute automatically when a stroke ends, and oas-change (detail { value }) fires with idempotent deduplication per value. clearable shows a "Clear" button; clear() programmatically clears the pad (idempotent — no-op when already empty). A single tap (press-and-release without movement) does not count as a stroke — no value is produced and the state does not flip; an in-progress stroke only follows the first pointer, so a second finger or palm never pollutes it.
Controlled Value
Controlled echo (sign → readonly echo pad)
Sign here
Readonly echo pad on the right
Writing value from the host (e.g. copying the left pad's dataURL to the right one) renders it as a controlled echo: local strokes are cleared and the external image is loaded (contain, centered). Writing back the very value the component just dispatched does not trigger a clear (no controlled-loop oscillation). Use toDataURL() to read programmatically: it returns an empty string for an empty pad.
Disabled & Readonly
disabled / readonly
disabled: no signing at all
readonly: strokes stay visible, edits blocked
disabled / readonly are presence semantics: stroke start is blocked (moves/ups have no effect either). readonly keeps existing strokes and value; both grey out the clear button.
Stroke Styling
pen-size / pen-color / height
pen-size=4 · pen-color=blue
pen-color=#c41d7f · height=120
pen-size defaults to 2 (px; invalid values fall back). pen-color accepts 11 preset names (magenta / red / volcano / orange / gold / lime / green / cyan / blue / geekblue / purple, resolved via --oas-preset-* tokens with dark variants) or any CSS color; the default var(--oas-color-text-primary) follows the theme — theme switches re-resolve and repaint strokes automatically. height controls the pad height (px, default 160); the width fills the host at 100%.
Dark Theme
Signature pad in dark theme
The default stroke color is --oas-color-text-primary, which flips to a light tone in dark mode; the pad background/border use the --oas-color-bg-elevated / --oas-color-border tokens.
Accessibility & forced-colors
The canvas carries role="img" with a stateful accessible name ("Signature pad, not signed / signed") and announces state flips through an aria-live="polite" region; the clear control is a native keyboard-reachable button with a focus-visible ring. Under forced-colors (Windows high contrast) canvas strokes cannot be system-recolored — a canvas limitation. In v1 the pad keeps a 1px border so its bounds stay visible, and no DOM stroke replica is provided; contrast of the signature image is the host's responsibility via pen-color.
Edge Cases
- Theme observation only listens at the
documentElementlevel (class/data-themeon<html>); a runtime container-leveldata-themeswitch does not re-resolve the pen color immediately — it takes effect on the next repaint (e.g. a container resize). If a resize or theme switch happens mid-stroke, the already-drawn segments are fully preserved by the repaint; no stroke is lost. - Setting
disabled/readonlymid-stroke lets the current stroke finish normally (its captured trail is fully committed tovalue); new strokes are intercepted starting from the next one.
API
oas-signature
Attributes
| Attribute | Description | Type | Default |
|---|---|---|---|
clearable | Show clear button | boolean | — |
disabled | Disabled (blocks drawing) | boolean | — |
height | Canvas height (px, default 160) | string | 160 |
pen-color | Stroke color (11 preset names or CSS color, defaults to theme text color) | string | — |
pen-size | Stroke width (px, default 2) | string | 2 |
readonly | Readonly (blocks drawing, keeps strokes visible) | boolean | — |
value | Signature image (PNG dataURL), two-way bindable | string | — |
Methods
| Method | Signature | Description |
|---|---|---|
clear | clear(): void | Clears the canvas and strokes; resets value to empty and dispatches oas-change by fingerprint |
toDataURL | toDataURL(): string | Current canvas PNG dataURL; returns an empty string when the canvas has no strokes and no external image, or when canvas is unavailable |
Events
| Event | Description |
|---|---|
oas-change | Dispatched on stroke end or clear (idempotent per value), detail: { value: url } | { value: '' } |