Controls made of rows over a table of radios, a fieldset of radios, checkboxes and a file input
Four more controls from ui-feed.dev, rebuilt with HTML-in-canvas. Each one is a stack of rows: the requests of a page as it loads, a list of playback speeds, a list of flavours and a list of files. Underneath they're a table, two fieldsets and a list, which lay out as plain rows. I wanted to know if the canvas could reshape the pictures of those rows (squeeze a number, scale a row to its share of the height, cut a row in two) and keep every row's native input working under the finger.
Credit: every control on this page is a rebuild of a demo on ui-feed.dev, and each section links to the original it came from. The originals are far higher fidelity than these, so go and look at them. These are examples of what HTML-in-canvas makes possible with a native element underneath, not replacements. I worked from the published demos rather than their source: I looked at what each one does, worked out the mechanism and built it again. The designs and the ideas are theirs. The shop, the files and the words in the notes here are my own.
Homepage waterfall
A figure of the requests a shop's homepage makes as it loads. The names and sizes are a <table>,
and each row header holds a radio, so a tap or the arrow keys choose a request and the form sends it. The canvas draws
the rest over the table's empty timeline column: the axis, the first and largest paint, a whisker for the time a
request waits and a block for the time it loads. The bars grow as the page arrives, at 1.8 times real speed, and the
chain from the stylesheet to the hero image is drawn in red. The figures under it are an <output> for
the chosen row.
After the homepage figure (waterfall) on ui-feed.dev.
Show the code the markup and the control
- The markup. One option for each request: its size, when it starts, how long it waits, when it ends, and which request named it.
- The control. The table of radios, the bars over it and the output.
- The base class. The shadow root, the canvas, the paint loop and the plain HTML fallback.
Playback speed
Five radios in a <fieldset>, one for each speed. The numbers are set in an ordinary bold sans-serif,
and the canvas draws the picture of each one again at 60% of its width, which gives a condensed face without loading
one. To do that it draws the fieldset once with the numbers cut out, then once more for each number, squeezed and
clipped to it, then puts the hit region back where the fieldset is laid out. The chosen number jumps on a spring and a
dot slides to it. With the keyboard, the focused row gets a line under it.
After the playback speed list (listbox) on ui-feed.dev.
Show the code the markup and the control
- The markup. One option for each speed, with the word under it.
- The control. The radios, the squeezed numbers and the dot.
Flavours
Six checkboxes in a <fieldset>, each covering its row, so you can pick as many as you like and the
form sends each one. The coloured dots are in the picture of the fieldset. The canvas draws a white bar under the row
that has focus, which a tap gives too, and moves it on a spring from row to row. Each tick is drawn along its path as
the box is checked, and back again when it's cleared.
After the flavours list (multiple select) on ui-feed.dev.
Show the code the markup and the control
- The markup. One option for each flavour, with its colour.
- The control. The checkboxes, the bar and the ticks.
File list
A <ul> of files, each with a remove <button>, and a <label>
round an <input type="file" multiple> for the last row. The rows always share the whole height, so
when a file goes the others grow, type and all, and when files are added they shrink. Each row is laid out once at
72 pixels and drawn scaled to its share, in two pieces: the name from the left, and the button moved to the right
edge so it stays in the corner at any size. The form sends the files, and an <output role="status">
says what was added or removed.
After the stacked file list (file input) on ui-feed.dev.
Show the code the markup and the control
- The markup. One option for each file the list starts with.
- The control. The list, the file input and the rows drawn in two pieces.
How it works
Each control is a custom element on the same base class as the scene controls. Its
shadow root holds a canvas with content="drawable", and the native elements are children of that canvas.
All four lay out as plain rows. The canvas then changes the picture of those rows rather than the layout. The speeds are squeezed sideways, the files are scaled to fit the height, and the waterfall's bars are drawn over a table column that is left empty. A row drawn in pieces has its hit region where its last piece was drawn, so the last draw is the one that holds the input: the fieldset is drawn again with no alpha at its own place, and each file row ends with the piece that holds its button.
Live checks
Findings
- A picture can be squeezed with a plain
scale(0.6, 1)on the context. The numbers of the speed list are an ordinary bold sans-serif drawn at 60% of their width, so the condensed face costs no font download, and the radios underneath still take taps because the last draw of the fieldset is at its laid-out place. - A row of a list can be drawn in two pieces at different places, the name from the left and the button at the right edge, and the button takes the tap if its piece is drawn last. When every row is the same size, one draw of the list holds every button.
- While rows of different sizes are moving, only the row drawn last has its button where it is drawn, because one element has one hit region. They settle in about half a second.
- An empty column of a
<table>makes room for a drawing, and its cells can hold text for a screen reader in a transparent colour that leaves nothing in the picture. - At rest none of the four raised a paint event in 500 ms. Taps worked on an emulated Pixel 7; nothing here has been run on a real phone.