Customisable <select> with a canvas-drawn picker

A select with appearance: base-select has a picker made of ordinary HTML. I tested the two ways to combine that with HTML-in-canvas: a canvas inside the select that draws the options, and a select inside a canvas. Each select below is one <select> element with real <option> children. Open them with a tap, a click or the keyboard.

Show the code a picker drawn by a canvas
  1. Write an ordinary select and add picker="…". The options are filled in by the page script here; they can equally be written in the HTML. The form reads the values as usual.
  2. Load the library. The rest of the page script fills in options and prints the form's values.
  3. Inside the library: move the options into a drawable canvas inside the select. A select collects options from all its descendants, so they remain its options.
  4. A layout is a function from an option's index to a matrix. This is the wheel. The fisheye, radial and carousel layouts have the same shape.
  5. The 2D route: one drawElementImage() per option. The call draws the option and moves its hit box to the same place, so the browser's own click, hover and focus handling choose options.
  6. The first paint event is the "picker opened" signal. A select fires no event when its picker opens.
  7. The carousel layout returns a matrix with perspective.
  8. The WebGL route: each option is a texture, uploaded with texElementSubImage2D().
  9. After a GPU frame, updateElementGeometry() gives each option its hit box, using the same matrix as the shader.
  10. The WebGPU route uploads with drawElementImageToTexture().
  11. Choosing and closing from script. There is no hidePicker(), so an empty popover is shown to close the picker.
  12. The options are styled with CSS.
  13. The whole library.
<script type="module" src="/lib/select-picker.js"></script>

<select name="time" picker="wheel">
  <option>09:00</option>
  <option>09:30</option>
</select>

Three more layouts, and a canvas in the button

The same library with three more layout functions. In the first and last select here the button also contains a canvas: it draws the <selectedcontent> element, and when the value changes the old value rolls out and the new one rolls in.

Show the code more layouts, and the button
  1. The markup. A <canvas> around <selectedcontent> in the button is optional.
  2. The hand of cards rotates each card about a point below the canvas.
  3. The grid scales and displaces each option by its distance from the pointer.
  4. The helix is a 3D layout, drawn with WebGPU or WebGL.
  5. rollSelected(select): a canvas in the button. The browser still fills in <selectedcontent>. The canvas keeps the picture of the old value and draws both during the change.
  6. The page script fills in the options and calls rollSelected().

A canvas inside each option

The card is a form drawn into a canvas with a 2D filter. The select next to it chooses the filter. Each option holds a small canvas that shows the card as it is now with that option's filter applied, so the previews keep the clock's current time and whatever is typed in the field. The button shows the chosen option through <selectedcontent>, which clones the option's canvas element without its pixels, so the page draws the clone as well.

Boarding pass

Show the code previews inside options
  1. The card is a drawable child of one canvas. Each option holds its own small canvas.
  2. The card's canvas keeps an unfiltered copy of its picture. An element can only be drawn into its own canvas, so the option canvases are given pixels with drawImage(), each with its own filter.
  3. <selectedcontent> replaces its clone on every change. A cloned canvas is blank, so the page draws into the new clone when it appears.
  4. The picker is styled with ::picker(select).

A select drawn in a canvas

Here the select is a drawable child of a canvas, and the canvas draws it rotated. The button is hit tested where it is drawn. The picker isn't part of the canvas: the browser paints it in the top layer, upright, anchored to the bounding box of the drawn button.

-12°
Show the code a select as a drawable child
  1. The select sits in a drawable element inside the canvas.
  2. One rotated drawElementImage(). Nothing is done for the picker.

Findings

More select modes to try

Live checks

These open small test selects in a panel at the bottom of the window. They need a tap to start because a picker only opens after one.