A <datalist> drawn by a canvas

The suggestions of <input list> appear in a popup that the browser draws. It has no pseudo-element, it ignores CSS, and it shows only each option's value and label. I wanted to know how much of a datalist a canvas can draw. The built-in popup is out of reach, but the <datalist> element and its options are ordinary elements, so they can be put in a canvas and drawn there.

Suggestions drawn one option at a time

Each field below is an <input list> with a <datalist>. A script moves the datalist into a canvas inside a popover and removes the input's list attribute, which stops the built-in popup. Type in a field: options that stop matching fade out and the rest move into the gaps. The arrow keys, Enter and Escape work as they do with a built-in datalist.

Show the code a datalist in a popover canvas
  1. Write an input with a datalist and add picker="list" or picker="chips". Without the library, or without HTML-in-canvas, this is a normal datalist.
  2. Load the library. The page script only fills the three datalists with <option value label> elements.
  3. Inside the library: stop the built-in popup and move the datalist into a canvas. The canvas is in a popover="manual" element positioned next to the input with CSS anchor positioning.
  4. Decide which options match.
  5. A layout gives each matching option a place.
  6. Each frame, move every option a little towards its place and draw it. drawElementImage() also moves the option's hit box, so a tap lands on the option that is drawn there.
  7. The keyboard. The browser's datalist keyboard handling went away with the list attribute, so this part is written by hand.
  8. Choosing an option sets the input's value and fires input and change.

Labels for the ticks of a range input

<input type="range" list> draws a tick mark for each option of its datalist and nothing else: the option's label is never shown. Here the range input and its datalist are both children of one canvas. The canvas draws the input, then draws each <option> under its tick, larger when the thumb is near. The labels are the real options. Tap one to jump to its value.

16px The quick brown fox jumps over the lazy dog.

Show the code datalist options as tick labels
  1. A range input with a datalist. The text inside each option is the label.
  2. One line in the page.
  3. Inside the library: both elements go into a canvas, which draws the input and then every option.

The built-in popup, with the input drawn in a canvas

This input keeps its list attribute and is drawn rotated by a canvas. Type in it. The expected result, by analogy with a select in a canvas, is that the built-in popup opens upright next to the bounding box of the rotated input, and isn't part of what the canvas draws. The test browser used for this page runs without a window and never shows that popup, so this isn't confirmed.

Findings

More to try with a datalist

Live checks

These run on test inputs in a panel at the bottom of the window, not on the fields above. They wait for a tap because they open test pickers on top of the page.