Five more select pickers drawn by a canvas

Each control below is one <select> with appearance: base-select. Its options have been moved into a canvas inside its picker, as on /select/, and the canvas does something a list of boxes cannot: it draws the same option twice, moves options with springs, places them on a plan, reads its own pixels, and keeps the chosen option on screen after the picker has gone. Open each one with a tap, a click or the keyboard. The values are read from the form in the usual way.

How it works

All five use the select picker library: the options are children of a <canvas content="drawable"> inside the select, and a layout function says where each one is drawn on every frame. The select still owns the value, focus, arrow keys, typeahead and the form entry. The listings below are the layouts.

Show the code the five layouts
  1. Five ordinary selects. The page script fills in the options.
  2. The page script gives each select its layout.
  3. Lens. place() draws every option small. over() draws the ones near the pointer again, enlarged, inside a clipped circle. The last draw of an option decides its hit box.
  4. Springs. Each option has a position, a velocity and a swelling. The transform is a translation, a skew and a squash.
  5. Seat plan. Each option carries its row and its place in the row as data attributes.
  6. Colour field. A press that hits no option reads a pixel, makes an <option> and chooses it.
  7. Option into the button. The option's rectangle is copied out of the picker canvas before the picker closes.
  8. The drawing loop in the picker library that calls these layouts.
  9. The options' CSS.

Live checks

These open a small test select in a panel at the bottom of the window. They wait for a tap because a picker only opens after one.

Findings