Form controls in a drawn setting
Four ideas from the element catalogue, built. Each canvas draws a scene and puts real form controls in it: labels pulled away from their fields, a date input on a wall calendar, a file input as the slot of a letter box, and a fieldset under frost. Tap a call-out, tap a day, post some files, and lock the panel. The text under each canvas is read from the form.
Exploded form diagram
One form. Each <label> is drawn as a call-out, away from its field, and the canvas draws the line between them. The fields are drawn sheared, as layers. Tap a call-out: the browser focuses its field. Type in a field, then press Send with a field empty.
The labels and fields are separate drawable elements, joined only by for. The canvas decides where each one is drawn. Focus, the checkbox toggle and the validation message come from the browser. The two lines of small text under a call-out are read from the field's type, required and validity.
Show the code
- Mark every label and every field
drawable. The form itself isn't drawn. - Draw each label, its field under a shear, and a line between them.
- Report what the browser did. No code here focuses anything.
- Styles.
Wall calendar around a date input
An <input type="date"> and an <input type="month"> are drawn on the top sheet of a calendar. Tap a day in the grid, type a date, or use the two buttons. When the month changes, the old sheet is torn off and falls, with a picture of the inputs as they were.
The two inputs hold the state. The grid, the month name and the red ring are canvas drawing made from their values. The falling sheet shows the old date because captureElementImage() took a picture of each input at the last paint, before the value changed.
Show the code
- Two inputs, two buttons and one element over the grid.
- Draw one sheet from a month, with the live inputs or with pictures of them.
- Tear off the old sheet when the month changes.
- Typing, the buttons and a tap on the grid all write the inputs.
- Styles.
File input on a drawn letter box
The slot in the brass plate is an <input type="file" multiple>. Tap it to choose files, or drop files on it. Each file drops through the slot onto the mat: a picture as a print, any other file as an envelope. Tap one on the mat to take it out of input.files.
The input's button and its count of files are the browser's own picture of the element. The page makes one <button drawable> for each file in input.files, and draws it where it has fallen, so each one can be tapped or reached with the Tab key there.
Show the code
- One file input in the canvas.
- Make one element for each chosen file.
- Draw the input on the plate, and each file on its way from the slot to the mat.
- A tap on a file writes a shorter list to
input.files. - Styles.
Disabled panel in one step
Tick "Lock this panel". That sets disabled on the <fieldset>, which disables every control in it except the ones in its legend. The canvas grows frost over the panel. Touch the frost: the patch clears and freezes again, and the control under it doesn't respond.
The browser greys the controls, takes them out of the Tab order and leaves them out of the form data. The page adds the frost: the fieldset drawn a second time through ctx.filter = 'blur()', a haze and crystal lines, clipped to a shape that grows from the edges.
Show the code
- One
drawablefieldset, with the lock in its legend. - The lock sets one attribute.
- Draw the fieldset, then the frost over it.
- A press on a disabled control still reaches the canvas.
- Styles.
How it works
Each canvas holds its controls as descendants marked drawable. A paint handler draws the scene with 2D calls and each control with drawElementImage(), which also moves the control's hit region to where it was drawn. The page uses 2D canvases only. A demo starts when its section comes near the screen.
- One design space. Every scene is laid out 380 units wide and scaled to the canvas, so a control is drawn smaller on a narrow phone and its hit region is scaled with it.
- The control is the state. No scene keeps a copy of a value. The paint handler reads
value,files,validityanddisabled. - A picture of an earlier state.
captureElementImage()returns a picture that stays as it was when the element changes. The calendar keeps two and callsclose()on each when its sheet has fallen. - Plain HTML when the canvas can't draw. Without the API, or after a lost context, the controls are moved out of the canvas and shown as an ordinary form.
Show the code
- Scale a 380 unit design space to the canvas.
- The paint loop, the draw helpers and the fallback to plain HTML.
- Each demo starts when its section comes near the screen.
Live checks
The checks wait for a tap. Each one builds its own small canvas in a corner of the window, or runs in a hidden copy of this page, and none of them touches the demos above.
Findings
Measured in headless Chromium 157 on 2026-11-21, with a mouse, a keyboard and emulated touch at 412 px wide. Nothing on this page has been run on a phone.
- A label works when it's drawn away from its field. The label and the field are separate
drawableelements joined byfor. A tap on the drawn label focused the text field, and a tap on the label of the checkbox toggled it. No code on the page moves focus. - A sheared field is hit inside its parallelogram.
getBoundingClientRect()returns the bounding box of the sheared shape (150 by 81 px for a 150 by 36 px field at a shear of -0.3).elementFromPoint()in the empty corner of that box returns the canvas. A tap near the raised end of the field focused it, and typing went into it. - The browser's validation message appears at the sheared field. After Send with the name empty, the message pointed at the field where the canvas had drawn it (seen in a screenshot).
- A picture from
captureElementImage()keeps the old value. A picture of a date input, taken before its value changed, matched the old pixels in every place after the change. The calendar draws those pictures on the sheet that falls. - Drawing a picture of an element moves the element's hit region. After the picture of an input was drawn 80 px lower,
getBoundingClientRect()of the live input reported the lower place. A draw of the input withglobalAlpha0 at its own place put the region back. The calendar does this on every frame of the fall. - A value written by script raises
paintand noinputevent. That holds for a date value, a month value andstepUp()on a month input. - A tap on a drawn file input opens the file chooser. The chooser reported
multiple. Files chosen there, and a file dropped on the drawn input, arrived ininput.fileswith achangeevent. - The file input's own text is in its picture. Writing
input.filesfrom aDataTransferchanged the pixels of the input (its count of files) and raisedpaint. That write raises nochangeevent, so the page updates its scene itself. - An element made for each file is tapped where it lies. Each print and envelope is a
<button drawable>appended to the canvas and drawn turned. A tap on one took its file out ofinput.files. - One
disabledattribute on a drawn fieldset does what it does outside a canvas. Every control except the checkbox in the legend matched:disabled, was left out ofFormDataand wasn't validated. The picture changed to the disabled colours andpaintwas raised. - A disabled control is still found, and a press on it still reaches the canvas.
elementFromPoint()returns the disabled button. A tap on it raisedpointerdownwith the button as target, and noclickon the button. The frost uses that press to melt a patch. ctx.filterapplies todrawElementImage(). Withblur(4px), a pixel beside a black and white edge read 93 where the plain draw read 0. Drawing the same element twice at the same place leaves its hit region where it was.- Not verified: everything on a phone. In particular the Android date and month dialogs opened from the calendar, the Android file chooser and camera from the letter box, large photos, the on-screen keyboard over a sheared field, and the speed of the blur. A screen reader hasn't been tried on any of the four.