Dates drawn over date inputs, text fields and radios

Five more controls from ui-feed.dev, rebuilt with HTML-in-canvas, all about dates: a night at a campsite, a best-before code, a library renewal, a wall calendar and the stops of a day out. The browser's own date picker is drawn by the system, outside the page, so a canvas can't draw it. I wanted to know how much of a date picker could be made from elements that stay in the canvas, and whether the one real <input type="date"> could still be typed in while it is drawn.

Credit: every control on this page is a rebuild of a demo on ui-feed.dev, and each section links to the original it came from. The originals are far higher fidelity than these, so go and look at them. These are examples of what HTML-in-canvas makes possible with a native element underneath, not replacements. I worked from the published demos rather than their source: I looked at what each one does, worked out the mechanism and built it again. The designs and the ideas are theirs.

Night at the lake

The field at the top is an <input type="date"> with a min and a max, so a date can be typed into it. The button opens a <dialog> with the open attribute, which keeps it out of the top layer and in the canvas. Each night in it is a radio with its price, and a night that is taken is a disabled radio. The canvas draws the rows of the month coming down one after another and a yellow disc under the night you picked. A night typed into the field that is taken makes the form invalid.

After the night at the lake (date picker) on ui-feed.dev.

Show the code the markup and the control
  1. The markup. One price for each night, and a dash for a night that is taken.
  2. The control. The date input, the dialog of radios and the draw.
  3. The base class. The shadow root, the canvas, the paint loop and the plain HTML fallback.

Best before

Three <input type="text" inputmode="numeric"> fields for the month, the day and the year, drawn with no alpha. A field that can't take another digit sends the caret on, Backspace in an empty one goes back, and the arrow keys count up and down. The canvas prints each figure in dots five wide and seven high, and the dots of a new figure spray in one column after another. A date that doesn't exist, such as 02/30, turns the boxes red and makes the form invalid.

After the can's best-before code (date input) on ui-feed.dev.

Show the code the markup, the dots and the control
  1. The markup.
  2. The dots. A five by seven font, and the spray.
  3. The control. Three fields, moving between them, and the value.

Library renewal

The receipt is one element. Its last line, "Return by", is the <summary> of a <details>, and the calendar inside it is a radio for each day. Days before today, days after the last day a loan can be renewed to, and the days the library is shut are disabled. As the details opens, the canvas draws more of the receipt and lifts it, so the paper looks as if it is coming out of the printer. Picking a day renews the loans due before it.

After the library loan renewal (date picker) on ui-feed.dev.

Show the code the markup and the control
  1. The markup. One option for each loan.
  2. The control. The receipt, the calendar of radios and the draw.
  3. A <details> that closes over time.

Wall calendar

A month of radios in a <table>, with two buttons to turn the page. The month is laid out twice: the teal copy holds the radios, and a coral copy, which is inert, holds only the weekends and the square behind the chosen day. The canvas draws the coral copy a fraction of a unit off the teal one, as a two-colour print sits on the page, and when the page turns the coral runs a little behind. The arrow keys move by a day or a week and cross into the next month.

After the two-colour wall calendar (calendar) on ui-feed.dev.

Show the code the markup and the control
  1. The markup.
  2. The control. Two plates, the page turn and the keys.

Day out

The stops are radios in an <ol>, so the arrow keys move between them. The list is laid out twice, once in a light weight and once in a heavy one that is inert. The canvas draws the heavy copy over the stop that has focus or is chosen, faded in over a fifth of a second, and grows a red dot on the line beside it.

After the day trip (timeline) on ui-feed.dev.

Show the code the markup and the control
  1. The markup.
  2. The control.

How it works

Each control is a custom element on the same base class as the pickers. Its shadow root holds a canvas with content="drawable", and the native elements are children of that canvas.

The picker of an <input type="date"> isn't part of the page at all, so only the field can be drawn. Everything that looks like a calendar here is a group of radios, one for each day, in a <table> or a list. A radio gives the arrow keys, a disabled state for a day that can't be chosen and a value for the form. The controls add what a group of radios doesn't do by itself: moving by a week, and crossing into the next month.

Two of the controls lay their content out twice. A canvas can only draw an element as it is, so a second copy with other styles (heavier type, or only the coral ink) is the way to fade or move one look over another. The copy is inert and hidden from assistive technology, and only the first copy takes input.

Live checks

Findings