Five more input pickers

Five controls, each on a real <input> element that keeps its value, its form entry, its input and change events and its keyboard handling, with a canvas doing the drawing. They're the ideas listed at the end of /inputs/. Each one asks a separate question of the API: drawing one element in slices, drawing under a set of buttons, reading pixels back from a canvas that draws elements, magnifying buttons, and drawing a datalist option inside an input.

A range input bent round a dial

The track, the thumb and the tick marks are the browser's own picture of <input type="range">. The canvas draws that picture in slices 3 px wide, each under its own rotation. Drag round the arc, or focus the dial with Tab and use the arrow keys, Home and End. The number in the middle is an <output> element drawn by the same canvas.

Show the code a range input drawn in slices round an arc
  1. The input is a child of the canvas. Its datalist gives it tick marks.
  2. One call.
  3. Inside the library. #paint() draws the slices with the nine-argument form of drawElementImage(). valueAt() turns the pointer's angle into a value.

A date range on one calendar

Two <input type="date"> elements share one calendar. Tap either field, tap the first day, then the last day. With a mouse the band follows the pointer between the two taps. By touch, press on the first day, slide to the last and lift. The band and the two discs are drawn by the canvas under the day buttons. On a keyboard, press Alt and Arrow Down in a field, move with the arrow keys and press Enter on each day.

Show the code two date inputs and one calendar
  1. Two ordinary date inputs.
  2. One picker for both. The popover opens next to the element that holds them.
  3. Inside the library: open the popover in place of the browser's picker.
  4. The band. Two day numbers move towards the chosen days a little each frame, and the canvas fills the cells between them.
  5. The whole picker. begin(), preview() and finish() are the three steps of a choice.
  6. The shared part that moves and draws the buttons.

A colour wheel that reads its own pixels

Tap the swatch. The wheel is two canvas gradients. Press on it and the pixel under the pointer is copied into a 1 by 1 canvas with drawImage(), read there with getImageData() and written to the input. During a drag the colour is worked out from the position, and the pixel is read again on release, so the canvas isn't read on every frame. The colours of the input's <datalist> are real buttons, each drawn on the wheel where its own colour is. The brightness slider is a real range input drawn by the same canvas.

Show the code a wheel, swatch buttons and a pixel read
  1. A colour input with a datalist.
  2. One call.
  3. Draw the wheel, then read one pixel of it. The read is in the same canvas that draws the buttons.
  4. The whole picker. spot() gives the place of a colour, which is where its swatch button is drawn.

A week picker on a year view

Tap the field. Every week of the year is a button, drawn at about half size in rows of thirteen. The weeks near the pointer or finger are pushed apart and drawn larger. Slide over the weeks and lift to choose, or tap one. The arrows step the year. A year has 52 or 53 weeks: 2026 has 53.

Show the code 53 week buttons under a fisheye
  1. An ordinary week input.
  2. One call.
  3. Inside the library. base() is the small grid and place() applies the fisheye to it.

Ghost text from a datalist

Type the start of a station name, for example Le or new. The rest of the first matching <option> is drawn after the caret at reduced opacity. Tab, Arrow Right or End accepts it, and so does a tap on the dimmed text, because the option is hit tested where it is drawn. Escape hides it. The input and the options are children of one canvas, which draws the input and then part of one option.

Show the code an option drawn at the caret
  1. The input and its datalist are children of the canvas.
  2. One call.
  3. Inside the library. #paint() measures the typed text with measureText() and draws the option from that point with the nine-argument form of drawElementImage().

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.

Findings