Skip to content

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 documentElement level (class / data-theme on <html>); a runtime container-level data-theme switch 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 / readonly mid-stroke lets the current stroke finish normally (its captured trail is fully committed to value); new strokes are intercepted starting from the next one.

API ​

oas-signature ​

Attributes ​

AttributeDescriptionTypeDefault
clearableShow clear buttonboolean—
disabledDisabled (blocks drawing)boolean—
heightCanvas height (px, default 160)string160
pen-colorStroke color (11 preset names or CSS color, defaults to theme text color)string—
pen-sizeStroke width (px, default 2)string2
readonlyReadonly (blocks drawing, keeps strokes visible)boolean—
valueSignature image (PNG dataURL), two-way bindablestring—

Methods ​

MethodSignatureDescription
clearclear(): voidClears the canvas and strokes; resets value to empty and dispatches oas-change by fingerprint
toDataURLtoDataURL(): stringCurrent canvas PNG dataURL; returns an empty string when the canvas has no strokes and no external image, or when canvas is unavailable

Events ​

EventDescription
oas-changeDispatched on stroke end or clear (idempotent per value), detail: { value: url } | { value: '' }

Released under the MIT OR Apache-2.0 License.