Choosing a control
Switch, Checkbox, RadioGroup, Select: they all pick a value. The right one tells people when it takes effect and how many they may pick.
API Switch Checkbox RadioGroup SegmentedControl Toolbar SplitButton Toggle Select FilterMenu DropdownMenu NumberInput Slider Meter ColorPicker Tabs Frame ContentFrame Label Button
A Switch acts the moment it flips. A Checkbox waits for a submit, or picks items from a set. Exactly one of a few is a RadioGroup; exactly one of many is a Select.
On the left, the Settings demo's editor section. Its settings apply as they change, so the on-off ones are Switches; the language new files open as has too many options to show at once, so it is a Select; and the three ways to indent are worth seeing side by side, so they are a RadioGroup. On the right, Mail's conversations do nothing until Archive, so each row has a Checkbox. Tick one, and the box above them turns partly checked; press it to select none.
Do and don't#
Use a Switch for a setting that applies immediately, with no Save button after it.
Put Switches in a form with a Save button: nobody can tell whether a flip already took effect.
Show two to five options as a RadioGroup when people should compare them before choosing.
Hide three options in a Select to save a few lines: the choice costs a tap to open and the options cannot be read side by side.
Which one#
| The choice | Takes effect | Use |
|---|---|---|
| One setting, on or off | Immediately | Switch |
| One yes or no in a form, or agreeing to terms | On submit | Checkbox |
| Any number of items from a set: filters, facets, a bulk selection | On apply or submit | Checkbox list |
| Exactly one of two to five, worth seeing together | Either | RadioGroup |
| Exactly one of many, or of options with long names | Either | Select |
| One of two or three modes of the tool in hand, in its toolbar | Immediately | SegmentedControl |
| One of a few icon toggles in a toolbar: an alignment | Immediately | ToolbarGroup with selection="single" |
| Any number of tags or filters over a list, each on or off | Immediately | Toggles, side by side |
| Exactly one of a list too long to scan, or one that grows with people's own data: a task, a person, a label | Either | FilterMenu, behind a SelectButton that shows the pick |
| Any number of a short set the app fixes, from a menu: a release's tags, a view's options | Immediately, each pick | DropdownMenuCheckboxItems in a DropdownMenu |
| Any number of a list too long to scan, or one that grows with people's own data: labels, assignees | Immediately, each pick | FilterMenu with selection="multiple" |
| A number people know exactly: a count, a port, a font size | Either | NumberInput |
| A value along a range, where the exact number matters less than the feel | Either | Slider |
| None: a quantity read against its limit, seats taken or storage used | Read only | Meter, not a disabled Slider |
| A colour | Either | ColorPickerPopover, with the app's palette as swatches |
| One of a few panels of the same thing, each shown under the tabs in turn | Immediately | Tabs: they switch what is shown, not a value that is saved. Framed with their panels where the set is one block among others; variant="pane" where it switches everything a pane shows |
| One of a few ways to draw what is already on screen, with no panel of its own: a message as plain text or as HTML | Immediately | SegmentedControl |
| A block's drawing or its text as written: a diagram, a patch, rendered Markdown, an HTML page, a message, a tree | Immediately | ContentSourceToggle in its header, held down while the text shows |
A SegmentedControl sets how the tool works rather than a value it saves: the Binary inspector's
typing mode, Overwrite or Insert, beside the commands it changes. A setting on a form or a settings
screen, even one of two, is a RadioGroup. Icons that pick one of a few in a toolbar, an alignment,
are a ToolbarGroup with selection="single": short of room it keeps its row until it moves into
the ⋯ whole, where a SegmentedControl first becomes a dropdown of its words
(Toolbars).
A setting that changes one of a SegmentedControl's choices, rather than being one of them, goes in
a SegmentedControlMenu at the end of its run: the theme menu's Use AMOLED, which turns Dark into
AMOLED, waits behind the ▾ after Auto, Light and Dark. Collapsed to a dropdown or moved into the
⋯, the run keeps it, after its choices.
A SplitButton does the usual thing on its face and offers the others behind its arrow. Use it
when one variant is what people want most of the time; when none is, the variants are a menu of
their own.
A Toggle narrows what is on screen the moment it is pressed, and any number may be on: the Notes
demo's tags above its list. Filters that wait for Apply, or a choice the app saves, are a
Checkbox list.
The parent of a partly checked list is a Checkbox with checked="indeterminate". A Switch has no
indeterminate state and no "applies later": if the setting only takes effect once
something else happens, it is not a Switch.
The Settings demo's profile form keeps its choices until Save profile, so its one yes or no is a Checkbox. Its time zone is one of thirteen, too many to lay out side by side, so it is a Select.
A task is a duplicate of one of sixty others. A Select would make people scroll for it; people
already know a word of its title or its number, so FilterMenu lets them type it. The trigger is a
SelectButton, drawn as a Select's trigger, so the field reads as one: as tall as the fields beside
it on touch, in their type rather than a button's heavier one, and sunk into the form under a style
that sinks fields. It names the pick, and the menu closes on it. Use it once a list runs past what fits on
one screen, or holds things people add themselves, whose number nobody can promise; a fixed set
that fits, like the time zones above, stays a Select. A FilterMenu whose rows are places, a
project switcher, goes rather than picks: each row is a link
(Navigation). A long list that one
of a menu's actions opens, moving a task to another project from its ⋯ menu, stays in that menu as
a submenu that filters the same way (Overlays).
A row with a few variants of its own, such as a theme's accents, keeps them under it:
getSubmenu gives them, and submenus="inline" opens them in place from the row's ▾ or →, the
group holding the pick open as the menu opens. They stay in the one list the arrow keys walk, and
the row itself is still picked with one click. A row whose own list is long enough to want a filter
box of its own opens it beside the menu instead, the default, with submenuFilter.
A pick that should leave the menu open calls event.preventDefault() in onSelect: one whose
result comes later, where the menu closes once it has, or a row that only completes the query, as
a reference picker's Europe… writes Europe: into the box and lists what is in it.
Rows that come from a server arrive after the menu opens and after each query. Until they do, pass
loading: the list draws placeholder rows where they will stand, which wait as any skeleton does
(Loading, empty & error), and empty is kept
for an answer with nothing in it, so "No matches" never shows for a question still being asked.
Labels edits the labels on the tasks ticked below. With selection="multiple" each row is
on or off by itself, and each pick takes effect at once while the menu stays open for the next. A
label on only some of the tasks is partly picked, through mixedIds. A pick gives it to all of
them, the next takes it off all of them, and the one after puts it back on just the ones it was on
(event.mixed), so a slip costs two more picks rather than the tasks' own labels. Put what is
picked first as the menu opens and as the query changes, never as a row is picked, so nothing moves
under the pointer. A row that does
something rather than being one of the choices, Create “…”, is an action: it takes no box.
A DropdownMenuCheckboxItem ticks with the same box, so a short set in a DropdownMenu and a long
one in a FilterMenu read alike, and the list's length decides between them, not the look
(Overlays).
function greet(name) {People know their font size by its number, and pick it a pixel at a time, so the Settings demo's
is a NumberInput: type it, or step it with the arrows beside it or the arrow keys, and the line
of code under it follows each step. A Slider of a few stops would hide the number under a feel
nobody asked for. Put the unit in a word after the field, as here, not in the label.
A Slider is for what is judged by eye or by ear rather than read off: the place in a recording, a
volume. In the pull request demo's Checks, press Recording: its seek bar is a Slider. A screen
reader still reads out the number under it, so where that number is not what a listener would say,
seconds or a share of one, valueText gives the words: this seek bar says its place against the
recording's length, and a volume says a percentage.
A label's colour only tells it apart from the others, so the app's palette rides along as
swatches and most picks are one tap; the area and sliders above them are there for a colour of
one's own. Pass
format="hex" and alpha={false} when the colour is stored as a plain hex. Open the full
ColorPicker, without the popover, only where colour is the work itself, such as a theme editor.
2 comments on “feat: retry a failed fetch once before giving up”.
The tabs above show a pull request's conversation, commits and checks in turn, in a box on a page
about something else. Nothing is saved by picking one. Tabs are for switching panels: each tab has
one. A set that is one block among others in a surface's flow, as this one is, is drawn with its
panels as one Frame by Tabs variant="framed": the strip on the frame's lid, its FrameBar,
beside whatever else names or acts on the set, and the current tab cut out of the strip into its
panel. Where each would be a page of its own, with an address a reader sends to someone and Back
leaves, as the same parts of a pull request are in the Pull request demo,
they are places: a TabNav of links (Navigation). A switch
with no panel under it, one that redraws what is already on screen, is a SegmentedControl. A
block's text as written is not one of its views in this sense: the drawing and the text are one
thing read two ways, so the block's header holds Source, a toggle held down while the text
shows, rather than a pair of tabs.
Tabs that switch everything a pane shows below its header, as a release's overview, log and diff
do in the Releases demo, are the pane's own rather than a block in it:
Tabs variant="pane" runs the strip across the pane's row, its rule meeting the pane's sides,
and the current panel fills the rest of the pane and scrolls on its own. Framed, the set would
draw a second edge inside the pane's and take a gutter from every panel.
On each platform#
Desktop & pointer#
- The label is part of the hit area: pair every control with a
LabelthroughhtmlFor, so a click on the words toggles it. - Space toggles a Switch or Checkbox; the arrow keys move within a RadioGroup, and Tab leaves it.
- Rows stay compact. A settings list reads as a column of labels with the controls on one edge.
Touch#
- The controls take their touch sizes on a coarse pointer by themselves; there is no prop to set. Touch, above an example, previews them.
- In a settings list, put the label on the leading edge and the Switch on the trailing edge, as the phone's own settings do.
- A Select opens a list the width of the trigger: keep option names short enough to read in it.
In the demos
- SettingsEditor's Switches apply as they flip, with no Save button, and its preview follows, as it follows each step of the font size NumberInput. The language is a Select of many and the indent a RadioGroup of three. Profile's Checkbox waits for Save profile.
- AdminSeats and storage are Meters, read against their limit and set nowhere here; storage nearly full turns the warning colour. In Settings, Require two-step sign-in is a Switch that applies as it flips.
- TasksEach filter is a menu you can search, picking one status, person or label, and it applies at once. List and Board is a SegmentedControl: two ways to show the same tasks, switched in place. Rows are picked with Checkboxes for the bulk bar, and New task picks its assignee and label from Selects.