Date, time and colour pickers drawn by a canvas
<input type="date">, type="time" and type="color" open pickers that the browser draws. A page can't
style them, and unlike a customisable select they have no part a canvas can go in. I tested two things. First, a replacement
picker in which every day, hour and swatch is a real button drawn by a canvas, on the same input element. Second, what happens to the
built-in controls and pickers when the input itself is drawn in a canvas.
Three pickers made of buttons in a canvas
Tap a field. The time field opens a clock: choose an hour, the hours fold into the centre and the minutes come out. Drag round the face
for single minutes. The date field opens a month: the arrows, a sideways swipe or Page Up and Page Down slide to another month. The
colour field shows the colours of its <datalist> in rings. On a keyboard, type in the field as usual, or press
Alt and Arrow Down to move into the picker.
Show the code pickers made of buttons in a canvas
- Ordinary inputs with a
pickerattribute.minandmaxon the date input disable the days outside them. - Load the library.
- Inside the library: open the popover in place of the browser's picker.
- The clock.
place()says where each button goes. The buttons of the ring that is not in use get a target at the centre with no opacity, so they move there and fade. - The calendar.
from()gives the incoming buttons a starting point off to one side. - The swatches.
- The shared part: each frame, move every button a little towards its target and draw it.
drawElementImage()puts the button's hit box where it was drawn, so taps, hover and the focus ring follow. - Writing the value back fires
inputandchangeon the input.
The built-in controls drawn in a canvas
This form is one drawable child of a canvas, drawn rotated. Every control in it is the browser's own. Type in the date, drag the range, tick the box, and open the pickers. The table below lists what was seen in the test browser.
Show the code a form of built-in controls as a drawable child
- The form is a drawable child of the canvas.
- One rotated
drawElementImage(). Nothing is done for any control.
| Control | Drawn rotated | Used where it is drawn | Its picker |
|---|---|---|---|
| date, time, datetime-local, month, week | Yes, with the segment that has focus highlighted | A click on a segment focuses that segment, and typing changes it | Not observed (see the findings) |
| number | Yes, with its spin buttons | Typing works | None |
| color | Yes | A click opens the chooser | Opens upright next to the bounding box of the drawn swatch. Not drawn by the canvas |
| range with a datalist | Yes, with tick marks | A click on the track sets the value at that point along the rotated track | None |
| file | Yes | The button takes the click | The operating system's dialog |
| checkbox, radio | Yes | Yes | None |
| progress, meter | Yes | Not interactive | None |
Findings
- The built-in date, time and colour pickers have no element. There is no
::picker()for an input,appearance: base-selectdoes nothing on one, and nothing can be put inside an<input>. A canvas can draw the control but not its picker. - Built-in controls draw and work in a canvas. All thirteen kinds in the form above are drawn by one
drawElementImage()under a rotation. Focus, typing in date segments, the range thumb and the checkbox follow the drawing with no code. - A built-in picker opens upright at the bounding box. The colour chooser opens next to the bounding box of the rotated swatch and is not in the canvas's picture. This is the same as the picker of a select in a canvas.
- A replacement picker can be made of real buttons. In the three pickers at the top each hour, day and swatch is a
<button>that is a child of a canvas in a popover. They keep focus,:hover,:focus-visible,aria-pressedand their accessible names while the canvas moves, scales and fades them. A button with no opacity is not drawn, and its hit box is moved away withupdateElementGeometry(). - The canvas draws what is not a control. The clock face, the hand and the disc under the chosen day are 2D drawing in the same canvas, under the buttons. They animate between values, which CSS on the buttons alone cannot do.
- Stopping the browser's picker. With a mouse, the date and time pickers open only from the small icon in the field, which the library hides with
::-webkit-calendar-picker-indicator. For a touch, the library makes the inputreadonlywhile its own picker is open, because a read-only date or time input opens no picker. Fortype="color"it cancels theclickevent. - Not verified on real hardware. These results are from Chromium 157 driven by Playwright with a mouse and emulated touch. That browser has no window, so the built-in date and time pickers were never seen, and whether the
readonlystep stops the Android date and time dialogs has not been tried on a phone.
More to try with inputs
- A range input bent round a dial. Draw the input in thin slices along an arc, and map the pointer's angle back to a value. The hit box is a rectangle, so the pointer mapping has to be written by hand.
- A date range on one calendar. Two
<input type="date">elements share one canvas calendar, and the canvas draws the band between the two chosen days. - A colour wheel that reads its own pixels. Draw a gradient in the popover canvas and read back the pixel under the pointer, with the datalist swatches drawn on top of it at the positions of their colours.
- A week picker on a year view. 53 week buttons drawn small as a year, with the weeks near the pointer magnified as in the fisheye select.
- A file input that shows the files. After a choice, draw thumbnails of the chosen files as a fan of cards next to the drawn input.
- The controls of a
<video>or<audio>element. These are built-in controls too. See /select/ and the media experiments in the menu for related work.
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.