Small controls drawn over radios, toggle buttons, a password field and checkboxes

Five more controls from ui-feed.dev, rebuilt with HTML-in-canvas. They are small ones: a carousel of typefaces, a bold, italic and underline toolbar, an avatar that comes back online, a password field with an eye, and a list of newsletters. Each is one or two native elements, and the work is in how they move. I wanted to know whether the canvas could give each one its motion while the elements keep their keys, their state and what they say to a screen reader.

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.

Type styles

A radio for each typeface, drawn as the dots under the cards, so the arrow keys and the form value are the radio group's. The cards are one row of elements, and the canvas draws each card as a slice of it, squeezed across as it moves away from the middle, so the "Aa" on a card at the side is drawn narrow. Drag the cards, tap one at the side, or use the dots.

After the type styles (carousel) on ui-feed.dev.

Show the code the markup and the control
  1. The markup. One option for each card, with the CSS of its "Aa".
  2. The control. The radios, the drag and the cards squeezed from one row.
  3. The base class. The shadow root, the canvas, the paint loop and the plain HTML fallback.

Text formatting

Three <button aria-pressed>s in a role="toolbar", with Left and Right moving between them and Ctrl+B, Ctrl+I and Ctrl+U (Command on a Mac) pressing them. Each names a role="tooltip" card in aria-describedby, filled in with its name and shortcut, which springs up over the button you point at or focus. A pressed button's plate grows into place behind it, and the line under the bar takes the marks.

The quick brown fox jumps over the lazy dog

After the text formatting toolbar (tooltip) on ui-feed.dev.

Show the code the markup and the control
  1. The markup. The marks to start with, and the line they act on.
  2. The control. The toggle buttons, the keys and the tooltip.

Back online

The avatar is a <button aria-pressed>, pressed while the person is online. Away, it is a ring with thin initials and a moon. Pressed, a dark disc grows out of the status badge across the avatar, with a bold copy of the initials drawn only inside it, and the moon turns into a ring. An <output role="status"> says which.

After back online (avatar) on ui-feed.dev.

Show the code the markup and the control
  1. The markup. online starts it online.
  2. The control. The button, the bold copy and the fill from the badge.

Show and hide

An <input type="password"> whose own text is transparent. The canvas draws a dot for each character, popping in on a spring, at the place an invisible copy of the text in the same font says that character is, so the dots stay under the caret. The eye is a <button aria-pressed> that switches the field to text: the dots fade and the field's own letters show. The line fills as you type and goes green at the minimum length, and until then the form is invalid.

After show and hide (password) on ui-feed.dev.

Show the code the markup and the control
  1. The markup.
  2. The control. The field, the dots, the eye and the length check.

Newsletter topics

A checkbox in each row's label. The list is laid out twice: once in grey, which takes input, and once in white italic, which is inert. Each row is drawn as a slice of both, crossfaded on a spring, so a row you choose turns italic and white as its red dot fills.

After the newsletter topics (listbox) on ui-feed.dev.

Show the code the markup and the control
  1. The markup. One option for each newsletter; a selected one starts chosen.
  2. The control. The checkboxes, the italic copy and the dots.

How it works

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

These ones are mostly about motion that an element can't do to itself. A card is drawn squeezed by scaling the context before its slice is drawn, a fill is clipped to a growing circle, a dot pops on a spring, and a row crossfades between two copies of a list. The element underneath is still where the keys, the pressed state and the value live.

Live checks

Findings