Blocks to handle: legend, summary, figure, template and a table of buttons
Five ideas from the element catalogue in which the canvas turns a block element into a thing to pick up, pull or press: fieldsets as a stack of folders, a details element worked by a lever, figures as prints on a table, one template cloned into many tickets, and a table of buttons as a minefield. Every part that takes a tap is the element itself.
Folder tabs from legends
Three <fieldset> elements drawn as a stack of folders. The <legend> of each is its tab. Tap a tab: that folder rises out of the stack and comes down in front. The fields of the front folder can be used.
The folders overlap, and where they do the one drawn last takes the input. Drawing them from the back to the front is therefore enough: the fields of a folder behind can't be tapped through the folder in front, and each tab can, because it stands above it.
Show the code
- Three
drawablefieldsets, each with a button in its legend. - Draw the stack from the back, and move a folder to the front on a tap.
- Styles.
Summary as a lever
A <details> element and a lever drawn by the canvas. Drag the red knob to the right: the content unrolls as far as the lever has gone. Let go and it falls to the nearer end. A tap on the summary, or Enter on it, throws the lever.
A closed <details> is only as tall as its summary, and its content isn't painted, so it can't be drawn half open. The element is opened as soon as the lever leaves its stop, and the canvas draws only a part of its height.
Show the code
- An ordinary details element.
- The lever sets how much of the content is drawn, and when the element is open.
Photo gallery with real alt text
Four <figure> elements drawn as prints fanned out on a table. Tap a print: it comes forward, and the canvas writes the alt text of its <img> under it. Tap it again to put it back.
Each print is turned with ctx.rotate(), and its hit region turns with it. The image in it is still an <img>: a screen reader reads its alt, and a long press or right click on it is a press on an image.
Show the code
- Four
drawablefigures. - Fan them out, bring one forward, write its alt text.
Template stamped many times
One <template> with a ticket in it, cloned as many times as the slider says. Pick a layout: the tickets move to it one after another. Each ticket is a button that counts its own taps.
A <template> inside a canvas has no box and is never drawn. Its clones are ordinary children, and each has its own picture, its own hit region and its own state.
Show the code
- The template. The canvas has no other children in the markup.
- Clone it, and draw each clone at its place in the layout.
Minesweeper from a table of buttons
An 8 by 8 <table> with a <button> in every cell and 9 mines. Tap a cell. The cells it opens are opened in a wave that travels out from the tap, and each one is drawn enlarged for a moment as the wave reaches it. The first tap is never a mine.
The table is one picture. A cell is drawn enlarged by clipping a second draw of the table to the box of its <td>. The buttons take the taps themselves: the table is drawn flat, so each button is under the finger.
Show the code
- An empty
drawabletable. - The script fills it with 64 buttons.
- Open cells in a wave, and draw each new one enlarged.
How it works
- Drawing order is stacking order. A 2D canvas has no
z-indexfor the elements it draws. The folders, the prints and the tickets are drawn from the back to the front, and the element drawn last takes the input where two overlap. - Transforms carry the hit region. A print or a ticket drawn under
ctx.rotate()andctx.scale()is tapped where it is seen. - Canvas-drawn parts take input through the canvas. The lever isn't an element. A
pointerdownwhose target is the canvas itself is a press on a part that no element covers. - Frames. Each demo asks for frames only while something moves.
Show the code
- Each demo starts when its section comes near the screen.
- The paint handler shared by the five canvases.
- Place a block, and draw one piece of it.
- After a lost context the elements are shown as plain HTML.
Live checks
The checks wait for a tap. Each builds its own small canvas in a corner of the window, and none of them touches the demos above.
Findings
Measured in headless Chromium 157 on 2026-11-21. Not yet run on a phone.
- Drawing order is the only stacking order, and it's enough. Of two overlapping fieldsets the one drawn last took the input in the overlap, and the tab of the other was found above it. Three folders are reordered by changing the order of three draws.
- A legend can hold the tab's button. The legend's box (80 by 30 px in the check) is at the top of its fieldset, and
margin-leftmoves it along. The fieldset has no background of its own, so the space beside the tab is clear. - A closed
<details>can't be drawn part open. Closed, the element was 24 px tall, the height of its summary, while its content still reported a height of 48 px. The lever opens the element as soon as it leaves its stop and the canvas clips the draw: 66 of 138 px with the lever at 48%. - A click on the summary can be cancelled. With
preventDefault()the element stayed closed, so the summary, by tap or by Enter, throws the lever and the lever opens the element. - A canvas-drawn part takes input through the canvas. The knob isn't an element. A
pointerdownwhose target is the canvas, within 34 px of the knob, starts the drag, and atouchstartlistener cancels the touch so that the page doesn't scroll (0 px of scroll in a scripted touch drag). - A turned figure is tapped where it is seen. Under
ctx.rotate(0.5)the corner of an image was found at its turned place, and the place it would have had with no turn gave the canvas. - A template has no box, and its clones are independent. The template was 0 by 0 px with no client rectangles. Twelve clones were each found at their own place, and in the demo each of up to 18 tickets keeps its own tap count.
- Buttons in a table are hit-tested through the table's picture. 36 of 36 were found at their places. A disabled button is still what
elementFromPoint()gives. One change to a button raised one paint event. - Not verified: everything on a phone. Dragging the knob with a real finger, the long-press menu on a drawn image ("Save image"), the keyboard over the folder fields, and 38 px cells under a thumb.