Overlays

Dialog, Sheet, Popover, DropdownMenu, HoverCard and Tooltip: how much each one interrupts, and what it becomes on a phone.

Pick the overlay that interrupts least. A Popover or a menu keeps the page in reach; a Sheet sets it aside; a Dialog stops it until the question is answered.

Mail

Touch sizes for the toolbar icons

Access tokens

ci-runner

Pull request

alice opened this pull request

Each control opens a different overlay. In Mail, the panel icon opens the folders in a Sheet, the star is named by its Tooltip, and the tag icon opens the labels in a DropdownMenu that stays open for the next tick. On the token, the pencil edits its name in a Popover, and Revoke… asks in a Dialog. Hover alice for a HoverCard. Press Touch above the preview: the Tooltip and the HoverCard no longer open, and every other control still works.

Which one#

You need toUseBlocks the pageOn a phone
Ask one question, or take one short input, before going onDialogYesCentred, nearly full width; the footer buttons stack, primary on top
Show a panel of settings, filters or a navigation list beside the workSheet (side="right" or "left")Yes, dimmedThree quarters of the width, from the edge
Offer a short list of actions or one choice from a fewDropdownMenuYes, until a pick or EscapeRises from the bottom edge, the whole width, under a title bar; rows grow to touch size
Edit one value in place, where the trigger isPopoverNoOpens under its trigger, never wider than the screen
Explain a label, a setting or a section in a sentence or twoInfoPopoverNoOpens on a press, as on a click; see Writing
Preview what a link points toHoverCardNoDoes not open: the link itself must be enough
Name an icon buttonTooltipNoDoes not open: the aria-label names it, the icon must be clear

Open one overlay from another at most once: a menu or a Popover inside a dialog is fine. A dialog that opens another dialog is a flow; make it a page, or one dialog with steps.

A dialog or a sheet never grows past the screen. Wrap the part that can grow, a list, a diff or a long form, in DialogBody or SheetBody: on a short screen or a phone held sideways, that part scrolls and the question and its answer stay in view. One without it scrolls whole, which still reaches the footer but scrolls the title away.

Long submenus#

A submenu that lists what people add themselves, such as projects, people or labels, can grow past a screen. Give its DropdownMenuSubContent a query and onQueryChange, and pass only the rows the query matches: a filter box tops the submenu, typing filters rather than jumping to a row by its first letter, and the arrow keys walk the matches. matchText and MatchedText, which FilterMenu uses, match and mark the rows the same way. A short list that never grows, such as the ways to sort, needs no box.

  • Keyboard help for the demosATL
  • Undo after closing a taskEMB
  • Tag a release from the mirrorIND

Open a task's ⋯ menu and press → on Move to project, or rest the pointer on it: either way the box takes what you type, and Enter moves the task to the highlighted project. Escape closes the submenu and leaves the menu open. Press Touch above the preview: the box now waits for a tap, so the on-screen keyboard does not rise over the projects. On a phone the submenu takes the place of the menu's sheet, its box under the title bar, and the sheet sits on the keyboard once it rises.

Ticks and picks#

A menu that ticks marks each item with a box before its words, empty while it is off: a DropdownMenuCheckboxItem and a FilterMenu row under selection="multiple" draw the same box, with a dash in it for what is on only some of what is picked. A menu that picks one marks the pick with a check at the end of its row: a DropdownMenuRadioItem, and a FilterMenu row under single selection. So a menu that ticks says so before anything in it is ticked, and an item that toggles, Watch, reads apart from one that acts, Copy link, beside it.

A short set the app fixes, such as Mail's few labels or a release's tags, is a DropdownMenu of check items; prevent each item's onSelect and the menu stays open for the next tick. One that is long, or grows with people's own data, such as a project's labels or its people, is a FilterMenu with selection="multiple", which adds a box to filter it (Choosing a control). Either way the rows tick alike.

Do and don't#

Icon set: lucide 1.59 picked up (week 5)

Do

Title a dialog with its question, "Delete … forever?", and put the action that answers it in the footer, named with the same verb: Delete forever.

Don't

Use a dialog to show information that needs no answer: a toast, an inline note or a Popover interrupts less.

claude-agentReviewer
Do

Put anything a HoverCard or Tooltip shows somewhere reachable without hover too: the page the link opens, or a visible label.

claude-agentReviewer
Don't

Hide an action inside a HoverCard: a phone cannot hover, and a keyboard reaches the card only through its trigger's focus.

Closing#

Every overlay closes on Escape, and a Dialog, Sheet, Popover and menu on a click or tap outside them. A toast is outside none of them: pressing one, or its action, closes no overlay, and Escape pressed among the toasts takes the focus back to the overlay rather than closing it. Focus returns to the trigger that opened them; from a Dialog or Sheet a menu's item opened, it returns where the menu hands it back, its trigger unless the menu says otherwise, since the item went with the menu. A Dialog, a Sheet, a DropdownMenu, a Select and any menu open as a sheet hold the page still while they are open, and the click or tap that closes one does nothing else: it follows no link and opens no other menu. A tap closes it as the finger lifts. A Popover, and a FilterMenu beside its trigger, leave the page live: the click that closes one also does what it would have done, so it can go straight to the next field. A Dialog or Sheet also has its own close button in the corner, so it can be closed with one tap on a phone, where there is no Escape key.

A Dialog whose title shares a row with commands on its subject (download, zoom, paging) puts them in a DialogTitleBar, ending with a DialogCloseButton in place of the corner one. The row is a toolbar: the title keeps its first 20 characters, the commands that do not fit go into a ⋯ before the close button, and the close button always stays.

A click outside a Dialog that holds typed input should not throw the input away: keep it for the next opening, or ask first. The click most likely meant to look at the page behind.

An overlay the reader reads in rather than answers, such as the attachment viewer, which takes most of a phone's screen, or a Sheet of a task's details, is a place to them, and Back is how they leave a place. Opening it takes an entry in the browser's history, so Back closes it rather than leaving the page behind. Paging, or opening another file from inside it, replaces that entry, so Back never walks through every file looked at. Its own close button steps back over the entry it took; opened from a link, it has none, and closing replaces the address instead. Where the app can find what it shows again, the address names it, so a reload or a shared link reopens it. AttachmentViewerProvider takes state and onStateChange for this: it reports each opening, page and close, and shows what the app gives it.

In another window#

An app may draw part of itself in a second window, such as a Picture-in-Picture window that keeps a call or a form in view over other apps. An overlay opened from there belongs there: a CommandTooltip, ConfirmDialog, DialogContent, DropdownMenuContent, PopoverContent, SelectContent or TooltipContent takes that window's document.body as its container. Without it the overlay opens in the main window, behind the one the person is working in, and they are left waiting on a question they cannot see. Any other overlay, such as a SheetContent or HoverCardContent, opens only in the main window, so the part drawn in the other window asks with a Dialog or a Popover instead.

A Dialog there is modal to that window alone: it keeps the focus, closes on a press of its scrim and holds that window's page still, while the main window scrolls as before. Wrapping the part in a PortalContainerContext with that body does for every overlay in it what each container does.

Closed, a menu, a Popover or a FilterMenu there hands the focus back to what opened it in that window, as it does here, and so does a dialog one of a menu's items opened: Escape or Cancel in a Toolbar's ⋯ lands on the ⋯, and the main window keeps whatever it had.

A DropdownMenu there works as it does here: opened from the keys, it starts on its first item, the arrow keys and a typed letter move through it, → enters a submenu, and a press outside closes it. While it is open it holds that window as it would hold this one, its page still and out of the pointer's reach, and leaves the main window alone.

On each platform#

Desktop & pointer#

  • A Popover, HoverCard or Tooltip opens beside its trigger and flips to the other side when there is no room; nothing needs placing by hand.
  • A HoverCard opens after a short hover and stays open while the pointer is over the card, so its links can be clicked.
  • Menus are fully keyboard-driven: arrows move, Enter picks, typing a letter jumps to an item. In a submenu with a filter box, typing filters it instead.
  • A menu people pick from, a DropdownMenu of radio or check items and a FilterMenu alike, opens at one width and never narrower than its trigger, so two pickers side by side open alike and one under a short button keeps its rows whole; a DropdownMenu's longer rows widen it, up to the room there is. A menu of actions is as wide as its trigger.
  • A Select opens its list over the field, the picked item on the value and its words where the value's were, so the choices around it are a short move away. Its rows stand in from the list's edge as a menu's do. position="popper" drops the list below the field instead, as a menu drops, where it should leave what is around the field in view.
  • A menu item that goes somewhere is a link, a DropdownMenuItem with asChild around an a. A plain click goes there and closes the menu; a click with a modifier, a middle click or a right click is the browser's (a new tab, a window, a download), and the menu stays open. A FilterMenu row that goes somewhere is a link the same way, through rowLink.
  • A submenu's trigger can go somewhere too, a DropdownMenuSubTrigger with asChild around an a, such as New task going to a new task in this project and its submenu to one in another. Hovering it or pressing → opens the submenu; a click goes there as a menu item's link does.

Touch#

  • On a phone, narrower than md (768px) with no fine pointer, a DropdownMenu, a FilterMenu and a Select open as a sheet that rises from the bottom edge, the whole width, rather than beside their trigger, which a thumb would have to reach for and a keyboard would cover. The rows are the same rows. A title bar names the menu, after its content's aria-label, a FilterMenu's listLabel or the field's label, else the trigger's name; when the trigger shows only a value, such as a sort button reading Newest, give the content an aria-label. Its close button, a tap on the page above and Escape close it. A tablet, most phones held sideways and a narrow window under a mouse keep the menu beside its trigger, and Touch above a preview changes the pointer, not the width. The width is that of the window the menu opens in: in a narrow frame, or a Picture-in-Picture window, under a finger, the sheet rises from that window's bottom edge.
  • A submenu takes the sheet's place: its row's words in the title bar, and ‹ before them to go back, as ← and Escape do. A FilterMenu row's › half opens its submenu the same way, and its ▾ opens rows kept in place under it (submenus="inline") right there in the sheet. A sheet opened from a toolbar's ⋯ menu takes over from that menu's sheet, and its ‹ hands back.
  • Nothing opens on hover. A HoverCard and a Tooltip never appear, so neither may carry the only copy of anything.
  • A submenu's filter box takes the focus only when tapped, so the on-screen keyboard does not rise over the rows it filters.
  • A tap on a submenu's trigger opens the submenu, even when the trigger is a link: a finger has no hover to open it with. Make the trigger's own place the submenu's first row, so a phone still reaches it.
  • A Sheet is the phone's side panel: the site's own navigation on a phone is one. Prefer it over a Popover for anything longer than a field or two, where the on-screen keyboard would cover a Popover.
  • A Dialog sits in the middle of the screen with the keyboard below it. Keep it short enough to fit above the keyboard: one or two fields.

In the demos