Repository navigation
FSHSP-266 feat(field-sign): add ui-field-sign, the handwritten signature field - #196
Merged
Merged
Conversation
LBU4SH
added a commit
that referenced
this pull request
Nov 24, 2026
… frame, undoable clear From the review of #196: - A previous signature can no longer vanish from the export. The field only accepts an image data URL (a remote URL tainted the canvas: toDataURL threw on pointerup and the form kept the old value while the screen showed the new stroke). An image that fails to load leaves the field empty instead of announced as signed over a blank box; in PNG a stroke drawn before it loads holds the export until it has, and a canvas that still refuses to be read back falls back to SVG. - Fixed frame: the box size at the first stroke becomes the signature frame, points live in it and the screen fits it into the box. A box shrinking afterwards (a rotated phone) scaled nothing and cropped half the signature out of the value; measured in Storybook, the export stays 608x352. - The recoloured previous signature is cached instead of allocating a full-size canvas per frame while drawing over it. - The echo guard is kept, with its real reason: `control.setValue(value)` does call writeValue. The test now goes through a FormControl and fails without the guard (the ngModel one passed either way). - Backspace undoes the last stroke and Delete clears; `undo()` brings back what `clear()` removed — one key no longer destroys the whole signature. - A lost pointer capture ends the stroke; buttons other than the main one (stylus eraser) do not draw; an invalid `exportColor` falls back to black (it made the SVG export invisible); the ink width is a registered <length>, read back in px whatever unit the hook uses; the state announces `requiredLabel`, `role="img"` taking no aria-required. - Docs in English, per FSHSP-267 merged meanwhile: MDX, argTypes, demo values and `///` comments (figma/component-vars.json regenerated). Template-driven, Reactive and Signal Forms stories, plus reactive-forms tests.
LBU4SH
added a commit
that referenced
this pull request
Nov 24, 2026
…rtColor tokens From the second review of #196: - The fixed frame left dead bands: once the box changed proportions (a phone rotated), the frame was centred with room around it, and ink drawn there was shown but outside the value — a truncated signature that `required` accepts. The box at the first stroke is now the signature's region, and the exported frame is that region grown to every stroke; the view only refits on resize, never under the pen, and points are clamped to the box. Measured in Storybook: widening the box then signing in the left margin grows the export from 488 to 860 px, ink to the edge. - Measuring that surfaced a layout bug present since the first commit: in an `auto` grid track the canvas' `height: 100%` did not resolve, so widening the box made the canvas taller than the box (644x465 in a 176px field), its lower part clipped. Definite tracks now. - `exportColor` is resolved to rgb() on a probe under the host: a `var(--token)` passed CSS.supports, then painted nothing in the SVG export (black in PNG). An unresolved var() or a non-colour falls back to black, with a warning. The test no longer relies on a CSS.supports fake no browser behaves like. - Undo after a clear made while the previous signature was loading reloads it (the PNG export stalled); clear() and undo() do nothing under the pen (a blank image passed `required`); `touch-action: none` only while the area can be signed, so a read-only signature lets the page scroll; the silhouette cache keys on the image element, not on a string fingerprint. - Docs: PNG may fall back to SVG (check the MIME type), the value is untrusted on the server, pick a theme-independent exportColor. New tests (ratio change, clamping, token / unresolved / invalid colour, reload on undo, clear under the pen, undo after Delete, PNG→SVG fallback) each fail against a mutation of the code they cover.
…ure field The field box IS the drawing area: a <canvas> projected into the `ui-field` shell, driven by Pointer Events — finger, stylus or mouse. Label, helper, levels and disabled/readonly come from the shell like every other field. - The value is a data URL (`format`: png or svg), `null` while empty, so `required` works as is. It leaves once a stroke ends, never mid-stroke: an autosave would otherwise get an image per pointer move. - Two inks. On screen the ink follows the tokens, dark theme included; the export is painted in `exportColor` on a transparent background. Measured in Storybook: a stroke drawn in dark mode exports with zero light pixels — without this split it came out white, invisible on the PDF it is for. - A value written by the form is shown, redrawn as a silhouette in the current ink (a black export stays legible on a dark field), and kept under new strokes until cleared. - `touch-action: none` + pointer capture: measured with CDP touch events, the page does not scroll under the finger; a second finger is ignored. - Clear button, public `clear()`/`undo()`, Delete and Ctrl+Z on the area. The smoothing lives in a pure module shared by the canvas and the SVG export, so screen and export cannot drift, and it is unit-tested without a canvas (jsdom has none). `floatLabel` is listed as undocumented on purpose: there is no value for a resting label to stand in for.
… frame, undoable clear From the review of #196: - A previous signature can no longer vanish from the export. The field only accepts an image data URL (a remote URL tainted the canvas: toDataURL threw on pointerup and the form kept the old value while the screen showed the new stroke). An image that fails to load leaves the field empty instead of announced as signed over a blank box; in PNG a stroke drawn before it loads holds the export until it has, and a canvas that still refuses to be read back falls back to SVG. - Fixed frame: the box size at the first stroke becomes the signature frame, points live in it and the screen fits it into the box. A box shrinking afterwards (a rotated phone) scaled nothing and cropped half the signature out of the value; measured in Storybook, the export stays 608x352. - The recoloured previous signature is cached instead of allocating a full-size canvas per frame while drawing over it. - The echo guard is kept, with its real reason: `control.setValue(value)` does call writeValue. The test now goes through a FormControl and fails without the guard (the ngModel one passed either way). - Backspace undoes the last stroke and Delete clears; `undo()` brings back what `clear()` removed — one key no longer destroys the whole signature. - A lost pointer capture ends the stroke; buttons other than the main one (stylus eraser) do not draw; an invalid `exportColor` falls back to black (it made the SVG export invisible); the ink width is a registered <length>, read back in px whatever unit the hook uses; the state announces `requiredLabel`, `role="img"` taking no aria-required. - Docs in English, per FSHSP-267 merged meanwhile: MDX, argTypes, demo values and `///` comments (figma/component-vars.json regenerated). Template-driven, Reactive and Signal Forms stories, plus reactive-forms tests.
…rtColor tokens From the second review of #196: - The fixed frame left dead bands: once the box changed proportions (a phone rotated), the frame was centred with room around it, and ink drawn there was shown but outside the value — a truncated signature that `required` accepts. The box at the first stroke is now the signature's region, and the exported frame is that region grown to every stroke; the view only refits on resize, never under the pen, and points are clamped to the box. Measured in Storybook: widening the box then signing in the left margin grows the export from 488 to 860 px, ink to the edge. - Measuring that surfaced a layout bug present since the first commit: in an `auto` grid track the canvas' `height: 100%` did not resolve, so widening the box made the canvas taller than the box (644x465 in a 176px field), its lower part clipped. Definite tracks now. - `exportColor` is resolved to rgb() on a probe under the host: a `var(--token)` passed CSS.supports, then painted nothing in the SVG export (black in PNG). An unresolved var() or a non-colour falls back to black, with a warning. The test no longer relies on a CSS.supports fake no browser behaves like. - Undo after a clear made while the previous signature was loading reloads it (the PNG export stalled); clear() and undo() do nothing under the pen (a blank image passed `required`); `touch-action: none` only while the area can be signed, so a read-only signature lets the page scroll; the silhouette cache keys on the image element, not on a string fingerprint. - Docs: PNG may fall back to SVG (check the MIME type), the value is untrusted on the server, pick a theme-independent exportColor. New tests (ratio change, clamping, token / unresolved / invalid colour, reload on undo, clear under the pen, undo after Delete, PNG→SVG fallback) each fail against a mutation of the code they cover.
…images, keep taps visible - An SVG value the field exported is read back and its strokes copied next to the new ones, instead of being nested in an <image> re-encoded on every edit. Only the field's own shape is recognised, rebuilt from the values read; anything else stays an image. - A previous signature that cannot be loaded emits `imageError`; the form's value is left alone (it may be readable elsewhere). - A single tap exports a 0.2px segment, which the SVG rounding cannot collapse to zero.
…values Third review: - SVG read-back: plain finite numbers only, explicit path grammar, every layer inside its viewBox and no stroke wider than it, no DOCTYPE, no colourless ink. A value whose ink the screen would clip stays an <image> instead of reaching the export flat. - An unreadable value is shown and announced as such (`unreadableLabel`), in error, and clearable; it stays the value until cleared or signed over (undo brings it back). - A tap with moves on the spot exports a dot; a resize mid-stroke is applied when it ends; a stroke is dropped when the field is disabled under the pen; points stay half the ink width inside the box, so the frame no longer grows edit after edit. - Public API narrowed to the component; the read-back is memoised per value and cannot throw on commit; an empty PNG (`data:,`) falls back to SVG; no empty ink group, and line breaks escaped in attributes.
… disable races Fourth review: - The read-back bound was inverted: the viewBox was grown by half the ink width instead of holding it. Every point, with the ink around it, must now fit the viewBox; a tap's segment counts in the stroke bounds so the field's own exports always pass. - A tap is detected on rounded coordinates, so jitter below the export's precision can no longer round to a zero-length segment. - SVG: a value emitted with a previous signature still loading is emitted again without it if it turns out unreadable; with no stroke over it, a previous signature is re-emitted word for word (undo of a clear) instead of re-exported. The first stroke's region is no longer dropped by a load error under the pen. - Disabled under the pen: the pointer handlers drop the stroke themselves, without waiting for the effect; an abandoned first stroke releases its region. - Scales keep six significant digits; the pointer rectangle follows a resize mid-stroke; the docs say an unreadable value leaves the control valid, and how to block it.
LBU4SH
force-pushed
the
feat/FSHSP-266-field-sign
branch
from
November 25, 2026 11:15
32b0e3b to
ac9bb74
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Jira: FSHSP-266. Follow-ups: FSHSP-269 (Figma component,
node-idfor the story), FSHSP-270 (React port).New
ui-field-sign(@4sh/ui-kit/forms/ui-field-sign): a handwritten signature field whose box is the drawing area — a<canvas>projected into theui-fieldshell, driven by Pointer Events (finger, stylus, mouse). Label, helper, levels,disabled/readonlycome from the shell; CVA viaBaseFormField.format:png|svg),nullwhile empty sorequiredworks as is. Emitted when a stroke ends, never mid-stroke. PNG exported at 2× the drawing area, the same on every device.exportColor(black) on a transparent background, otherwise a signature drawn in dark mode came out white.exportColoraccepts a token (var(--…)), resolved torgb(); an unresolved one or a non-colour falls back to black.clear(). An SVG the field exported itself is re-exported flat (its strokes copied, read back attribute by attribute with its geometry checked — anything else, or ink reaching outside its own frame, stays an<image>), so the value grows by the new strokes only. An image that fails to load is shown and announced as unreadable (unreadableLabel, error level, clearable), emitsimageErrorand stays the value until cleared or signed over (the control stays valid: the doc shows how to block it); in PNG the export waits for it rather than drop it.touch-action: none+ pointer capture; a second finger is ignored; a resize mid-stroke is applied when it ends; disabled under the pen, the stroke is dropped.readonly), publicclear()/undo()(undo()also restores a clear),Backspace/Ctrl+Zundo,Deleteclears.role="img"named by the label and described by its state (placeholder /signedLabel, thenrequiredLabel) then the message.ui-field-sign-strokes.ts): smoothing shared by the canvas and the SVG export, so screen and export cannot drift; unit-tested without a canvas. Internal, like the SVG read-back (ui-field-sign-svg.ts): the entry point exports the component and its two types only.floatLabelis listed inUNDOCUMENTED_INPUTSon purpose: the box is the drawing, there is no value for a resting label to stand in for.--ui-*hooks (generatedcomponent-vars+figma/README.mdcounts), registries (READMEs EN/FR,Overview.mdx,components-index.md), CHANGELOG[Unreleased].Tests:
ui-field-sign.spec.ts(48 cases, reactive forms included) +ui-field-sign-strokes.spec.ts(26) +ui-field-sign-svg.spec.ts(42).pnpm test(465), eslint,ng build ui-kit,docs:config:checkgreen.Four reviews (
senior-code-reviewer), addressed in e89cd01, b9b6b8b, 1c224f8, 934bf94 and 32b0e3b — see their commit messages. The tests added since the second one each fail against a mutation of the code they cover.Checked in Storybook (static build + Playwright, system Chrome):
exportColortoken exported as its rgb();touch-actionback toautoin read-only / disabled; Forms stories invalid → valid once signed;Ctrl+Z×2 back to empty;pointerupwith nopointercancel, value emitted,scrollYunchanged;disabledink =form-high-content-disabled;readonly/disabledrefuse the pen;<image>, old strokes still rendered; a tap with moves on the spot exportsM80 50L80.2 50;_errorshell, clear button enabled, axe 0 violations.Not covered: a real phone (only emulated touch), WebKit (Chromium only — the tainted-canvas case falls back to SVG), and no Figma
designlink yet (FSHSP-269).🤖 Generated with Claude Code