Actions & buttons

One primary action per surface, the rest quieter, and the rare ones in a menu. A button's look says how much it matters.

A surface has at most one primary button: the action most people came to take. Everything else steps down a variant, and actions used now and then move into a menu.

Touch sizes for the toolbar icons

A conversation from the Mail demo. Send is the one primary button, and it waits until there is a reply to send. Archive and Delete are ghost icon buttons, each with a name, and a tooltip that also shows its key. Forward and Copy link are used now and then, so they wait behind More actions. Archive or delete the conversation: the toolbar swaps in Move to Inbox, and the toast takes it back.

Do and don't#

Do

Make the action people came for the one primary button, and step the others down.

Don't

Give every action the primary look: nothing stands out, so people read every label to find the one they want.

Do

Label a button with a verb and its object, "Save profile", "Delete 3 files", so it still reads right out of context.

Don't

Label it "OK", "Submit" or "Yes": the button then only makes sense after reading the question above it.

Which variant#

The actionvariant
The one action the surface exists for: Save, Publish, Senddefault
A second action nearly as wanted, which the reader may take instead: Save draft, Schedulesecondary
An alternative or a way back beside it: Cancel, Back, Discard changesoutline
A repeated or toolbar action, usually an icon: Bold, Copy, Closeghost
An action that deletes or discardsdestructive, see Destructive actions
A navigation that looks like a link inside prose or a tablelink, or a real <a> through asChild

The variants rank. default is the primary itself, its words reversed out of it; secondary is a tint of the primary, edged in it, so it reads as an action of the same kind one step down; outline is a grey key, which any surface can hold several of; ghost is bare until the pointer reaches it. destructive is secondary in the destructive colour.

default, outline
ghost
destructiveci-runner
linkCI #1284 failedDetails

Each row is taken from a demo: the Settings profile form's footer, the Mail toolbar, an access token's row, and a failed run on the pull request's timeline, whose Details is a link.

The size follows the surface rather than the action: default in forms and dialogs, sm in dense rows and table cells, and lg only for a call to action that stands alone.

An action that leaves the page is a link (<Button asChild><a href>…</a></Button>), so it opens in a new tab and shows its address; an action that changes something is a button.

A verdict in colour#

An action whose outcome is good, risky or a loss in itself, such as approving, asking for changes or rejecting, can say so in colour as well as in words: intent stands the palette's success, warning or destructive (danger) colour in for the primary, in whichever variant the button has. default is filled with it, its words reversed out of it; secondary is its tint, edged in it, its words in its ink; outline and ghost keep their own look, with the icon in the colour. A DropdownMenuItem takes the same intent, its words and its icon in the colour, so a verdict offered in a menu reads as it does on a button, and a toolbar command or segment that moves into the ⋯ keeps its colour there.

feat: retry a failed fetch once before giving up#12

Where the view is for deciding and each button takes effect the moment it is pressed, the verdict the view expects is the one primary, in its colour, and the others step down to secondary in theirs. Press one: the review is decided at once, and its badge says how.

feat: retry a failed fetch once before giving up#12

Where the verdict is chosen and then sent with something else, a comment here, it is not an action yet: it is a SegmentedControl whose segments carry the intents, the chosen one held in its colour's tint, and the one primary is Submit review, in the primary's own colour. Nothing happens until it is pressed, and the verdict can change until then.

  • Give an intent to an action whose result is itself good news, a risk or a loss. Most buttons have none: Save is not a success, and a red that means "important" teaches people to ignore the red that means "gone".
  • The words carry the verdict, and the colour backs them up: "Approve", "Request changes", "Reject", never three coloured "OK"s.
  • An action that deletes stays destructive, which is secondary in the danger intent, as Destructive actions describes.

Overflow#

Put the actions a surface offers but people rarely take into a DropdownMenu behind a ghost icon button named "More actions". Keep the order stable: frequent first, destructive last behind a separator, each with variant="destructive".

Icon set: lucide 1.59 picked up (week 5)

A conversation in Mail's Trash. Open More actions: Forward and Copy link come first, and Delete forever… waits last, after a separator, in the destructive colour. Its ellipsis says it asks before it acts.

Do not hide the primary action in a menu, and do not put a single action in one: a menu with one item is a button that costs two taps.

Acting on a selection#

A list or tree whose rows can be selected heads them with a SelectionBar, a toolbar that starts with a select-all checkbox. While nothing is selected it holds the list's own toolbar; once a row is selected it says how many, offers the actions that take the whole selection, and ends with Clear selection.

  • main passed: 412 tests in 38sci
  • Review requested: tidy the Tabs touch sizesreview
  • Unread: Nightly visual diff: no changesci
  • Snapshot published under the master tagrelease

Select a second conversation, then press the checkbox in the bar: a partly checked box selects the rest, and a full one clears. Escape inside the bar clears too, and the focus stays on the checkbox. Drag the frame's corner narrower: the actions drop their words, then go into the ⋯, while the checkbox, the count and Clear selection stay.

  • Pass the parts of the list's toolbar as idle, and the actions as the bar's children: ToolbarButtons, a ToolbarMenu, a FilterMenu, as a toolbar takes them. They give way as its commands do, and the bar stays one Tab stop and one height whether or not anything is selected.
  • Put only the actions that apply to every selected row in the bar, icons first, a text action such as Delete forever… after them. The bar swaps them as the selection changes, as Mail's swaps Archive for Move to Inbox when the selection is archived.
  • An action that uses the selection up, as Archive does, or a Set status that moves the rows out of the list, clears the selection once it is done. The focus goes to the checkbox wherever in the bar the action was, on the bar, in its menu or in the ⋯, rather than falling to the page.
  • A list with no toolbar of its own mounts the bar only while something is selected. It is still there: on a touch screen, once a row is selected a tap selects too, and the bar's Clear selection is the visible way back.
  • An action on the whole list, such as Download all, sits at the end of the bar while nothing is selected, and gives way to the actions on the selection once something is: the selection is then what an action takes. An AttachmentList takes the first as listActions and the second as selectionActions; an action on one file stays on its row, as actions.
  • Select-all selects the rows the list holds now, never the ones still behind Load more.

A list that is not a Tree keeps its selection in useSelection, which feeds the bar its count and its select-all, and drops a row from the selection the moment the row leaves the list, so an action never reaches a row the reader no longer sees. A Table or a List takes it as selection: each row gives its key as value, its box is a TableRowSelect or a ListItemSelect, and a table's header box, or a group heading's, is a TableHeadSelect.

  • Shift-click selects a range: every row from the last one clicked to this one takes this one's new state, as in a file manager. Space on a box ticks it too.
  • A mouse selects many rows at once by sweeping: a press on a box dragged across the other rows selects every row the pointer crosses, anywhere on the row, or clears them when the first box was checked. Held at the edge of what scrolls, it scrolls on, and the rows it brings in count too. It starts only on a box, so a drag across a row's text still selects the text, and on touch the same drag still scrolls. Board, Tree and AttachmentList sweep on their own, as a Table and a List given a selection do; useSweepSelect is for a view the app draws itself.
  • Where a row leads with an icon, a SelectSlot lets the checkbox stand in for it, as a Tree's does: the icon until the pointer is on the row, the box from then on and on every selected row, and on touch on every row once anything is selected. The icon is the box's hit area, so a tap on it selects.

Acting on selected text#

An action that takes the words the reader picked out, such as Quote reply on a comment, comes to the selection with SelectionAction: under its last line for a mouse, or over its first when the window ends below it, and on a touch screen as a bar along the window's foot, where the platform's own bubble cannot cover it. The Pull request demo quotes a comment into the reply box this way.

  • Register each place a selection means something, a comment's body, with useSelectionRegion. A selection that runs out of it, into the comment's header or the next comment, offers nothing: the action would not know whose words they are.
  • A page that holds one document and nothing else to act on, a file's own view, may let its region take a selection that runs past its edge, with overflow: "clamp": a drag on past the end of the file, or Select All, then acts on the file up to its edge. The action is told which ends were moved there (clamped), since such an end lies between blocks rather than in a word. Where regions sit side by side, as comments in a timeline do, keep the default.
  • Regions drawn in a second window, such as a Picture-in-Picture window, go inside a PortalContainerContext with that window's document.body, the action with them (see Overlays). It then reads the selection made there and stays inside that window, clear of the bars its own scroll-padding marks.
  • Offer one or two actions, the ones selecting the text was for. Copying is the platform's already.
  • Where a selection inside the region leaves the action nothing to work with, words that map to no line it could point at, offer nothing: return null rather than a disabled button.
  • On a page with a sticky header or toolbar, declare it with useScrollInsets, as the page's own landings need anyway: the floating action then never covers the bar, and a selection scrolled under the bar takes the action under with it.
  • The floating action is a shortcut for a pointer. Where the keyboard needs the action too, keep it in the comment's menu as well: selecting text from the keyboard leaves no pointer to press it with.

On each platform#

Desktop & pointer#

  • An icon-only button has an aria-label, and a Tooltip that shows the same name on hover and on keyboard focus.
  • A frequent action gets a keyboard shortcut, shown in its tooltip or menu item (DropdownMenuShortcut).
  • Enter submits a form's primary action; Escape cancels a dialog, so neither needs a mouse.

Touch#

  • Tooltips do not open on touch. The aria-label still names the button for a screen reader, but an icon whose meaning is not obvious needs a text label on a phone.
  • Buttons take their touch sizes by themselves. Keep a row of them from wrapping into a second row that pushes content down: move the rare ones into the overflow menu instead.
  • In a dialog footer on a narrow screen the buttons stack full width, the primary one on top, within reach of a thumb.

In the demos