Lists drawn over text fields, checkboxes and radios

Five more controls from ui-feed.dev, rebuilt with HTML-in-canvas, all about choosing from a list: a language, which bin a thing goes in, the songs of a set, a city in an old window and a few cities printed in two colours. The picker of a <select> and the list of a <datalist> are drawn in the top layer, so a canvas can't draw either. I wanted to know how close a text field and a group of radios or checkboxes could get to a select and a combobox while they stay in the canvas.

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.

Language

A <details> whose <summary> shows the language, and a radio for each one in it. The list is laid out twice: once in black, which takes input, and once in white, which is inert. The canvas draws a black bar under the row you point at or move to with the keys, and the white copy only inside the bar, so the words change colour where the bar passes. The two ends of the bar are springs of different stiffness, so it stretches as it runs.

After the language select (select) on ui-feed.dev.

Show the code the markup and the control
  1. The markup. Each option is a radio, and its lang is set from the value.
  2. The control. The details, the white copy and the bar.
  3. A <details> that closes over time.
  4. The base class. The shadow root, the canvas, the paint loop and the plain HTML fallback.

Recycling bins

The heading is the text field: what you type replaces "Which bin?". Under it, a radio for each thing that matches, with the letters you typed in bold. The five bins are drawn by the canvas, not by elements, and each one is a set of springs: as you type, the bins that hold the matches come to the right of the list and the others shrink away, and when you choose, that bin grows and an <output> says what to do.

After which bin? (autocomplete) on ui-feed.dev.

Show the code the markup and the control
  1. The markup. One option for each thing, with the bin it goes in.
  2. The control. The field, the filtered radios and where each bin goes.

Setlist

Each song is a <button> in an <ol>, and the last row is a text field. Type a song and its length ("Encore 4:10") and press Enter to add it, and press Delete or Backspace on a song to take it off. The canvas draws each row as a strip of tape: a new one is torn off the roll, a removed one peels away while the rest close up, and the card adds up the set. Backspace in the empty field goes back to the last song.

After the setlist (token input) on ui-feed.dev.

Show the code the markup and the control
  1. The markup. One option for each song.
  2. The control. Adding, removing, the keys and the strips of tape.

1990s desktop

A text field with role="combobox", a button that shows every city, and a radio for each city in a list that is filtered as you type. An <output role="status"> says how many match, or "No results". The canvas draws the window, the bevels and the shadow, and unrolls the list in four steps rather than with a smooth ease.

After the 1990s desktop (combobox) on ui-feed.dev.

Show the code the markup and the control
  1. The markup.
  2. The control. The field, the button, the list and the window.

Two-colour cities

A checkbox for each city, a button for each checked one and a text field that filters the list. Enter checks the row the arrow keys are on, a click on a button or Backspace in the empty field unchecks one. The row of buttons is laid out twice: the blue copy takes input, and a yellow copy, which is inert, is drawn under it a little off, as a second colour sits on a print. Each change to the set is a new pass through the press, so the yellow lands off and settles.

After the two-color print (combobox) on ui-feed.dev.

Show the code the markup and the control
  1. The markup. A selected option starts checked.
  2. The control. The checkboxes, the buttons, the keys and the two plates.

How it works

Each control is a custom element on the same base class as the date controls. Its shadow root holds a canvas with content="drawable", and the native elements are children of that canvas.

The picker of a <select>, the list of a <datalist> and a popover are all in the top layer, which a canvas has no picture of. So each list here is a group of radios, or of checkboxes where more than one can be chosen, and the text fields filter them by setting hidden on the rows. A radio gives the arrow keys and a value; the controls add what a combobox does beyond that: Enter to choose, Escape to close, and the keys moving from the field into the list.

Three of the controls draw a copy of their own content. A canvas draws an element only as it looks, so a second copy with other styles (white text, yellow ink) is how one look is drawn inside or under another. The copies are inert and hidden from assistive technology.

Live checks

Findings