Craft

Anatomy of a combobox

  • Kitchen
  • Front of House

Choose one or more to filter the roster

Spatial rhythm

Spacing and grouping

People see things that are close together as a group, before they read a word. The label is 6px above the control and the help text 4px below it, so the three read as one field. The chips inside are 4px apart.

Rule

The space between an item and its parent is wider than the spacing among sibling items.

Height and overflow

The control is 40px tall, whatever is selected. It shows as many chips as fit its width.

Rule

The control can't grow. If it did, anything next to it in the same row would move each time someone picked an option.

Judgement

When the chips don't fit, the control could grow, which moves the row, or the chips could scroll, which cuts one in half and looks like a bug. I show a count of the hidden chips instead.

Colour and contrast

Edge and background

The combobox is meant for a white background, so this page shows it on a white panel. Its edge is 3.4 to 1 against that white. Against the page around the panel, it would be 3.1 to 1.

Rule

WCAG 1.4.11 asks for 3 to 1 between a control's edge and the colour next to it. The site's hairline grey is 1.3 to 1 against white, so the combobox uses a darker grey.

Text contrast

There are three kinds of text. The label is 14.4 to 1 against white and the chip labels are 12 to 1 against their pale blue. The help text is lighter, at 6.9 to 1, because people only need it the first time they use the field.

Rule

WCAG 1.4.3 asks for 4.5 to 1 between text and its background. On white, the lightest grey that passes is #767676. One step lighter, #777 fails at 4.48.

Focus ring

When the combobox has focus, its edge turns blue and a 2px blue ring appears around it. The brand blue is 2.9 to 1 against white, so the edge and the ring use a darker blue, at 4.7 to 1.

Rule

A focus indicator needs 3 to 1 as well, under the same WCAG 1.4.11. The 1px edge and the 2px ring make a 3px blue line, and it passes against white.

Semantics and accessibility

Field label

The label "Location" names the field on screen. The input is linked to it, so a screen reader announces the combobox as "Location". The list points to the same label and is announced as "Location" too.

Rule

WCAG 4.1.2 asks for every control to have a name that a screen reader can read out. A placeholder used as a label disappears once someone types. Without the link, the combobox is announced with no name, and without the shared label, so is the list.

Button names

Each selection has a cross that removes it. The cross at the end of the field looks the same and removes every selection.

Rule

A screen reader tells the crosses apart by their names, which WCAG 4.1.2 requires every button to have. Each chip's cross is announced as "Remove" and the chip's value, such as "Remove Kitchen", and the last one as "Clear all locations".

Typed text and value

Typing "win" narrows the list to Wing A and Wing C. The selected values, Kitchen and Front of House, are shown as chips and stay out of the text box. If someone types, changes their mind and leaves the field, the selection doesn't change.

Rule

What's typed in the box is a search. The value is the set of chips, and typing doesn't change it.

States and failure modes

Four states

A status changes the colour of the edge and the message underneath, and adds an icon in front of the message. The rest of the field stays as it is. Each status has its own icon shape, so the meaning doesn't depend on colour (WCAG 1.4.1): a diamond for error, a triangle for warning, a circle for success. Choose a state below to see each one.

State

Rule

All four states take the same space: a 40px control and a 20px message line. Every status edge is at least 3 to 1 against white, as WCAG 1.4.11 asks.

Help text and status

The help text and the status message both go on the line under the control, and there's only room for one. Here the error message has replaced the help text, and the line is still 20px tall.

Rule

The line under the control stays 20px tall even when it's empty, so a message can appear without moving anything below it.

Judgement

The status message replaces the help text until the status clears, so the instruction is hidden while someone is fixing an error. Showing both would make the field taller than the ones next to it. I haven't found a version of this that I'm happy with.

I design for people, not users.