Desktop & pointer

Hover hints, the keyboard reaches everything, and shortcuts speed up what is already on screen.

With a mouse, hover may hint and a shortcut may hurry, but every action is on screen and every control is reached with Tab. A desk is where these tools are used longest; it gets the density, and it gets nothing the keyboard or a thumb cannot also do.

Inbox
  • AliceTouch sizes for the toolbar icons
  • bot-oneRelease 0.9.0: changelog draft
  • CIFlaky test: retry-once times out on the slow runner

Hover over Refresh for its name, or Tab to it: the tooltip opens on focus too, and Compose's names its key, C. Each conversation's ⋯ button is always drawn, quiet and small, and opens with Enter or Space as well as a click; its menu prints each item's key, and an archive or a delete ends in a toast with Undo.

Hover#

Hover tells a person what they are about to press; it never holds the only way to press it.

  • The components draw their own hover states. Tailwind's hover: applies only where the primary pointer can hover (@media (hover: hover)), so a style you add with it does not stick after a tap on a phone.
  • A Tooltip names an icon button, and repeats the aria-label the button already has. It opens on hover and on keyboard focus; on touch it does not open at all.
  • A HoverCard previews what a link points to. Whatever it shows is also on the page the link opens.
  • Actions do not wait for hover to appear. A row's secondary actions sit behind a visible ⋯ button; a keyboard user and a phone have no hover to bring them out. A Tree is one Tab stop, so its menu draws ⋯ on the current row, the focused row and the row under the pointer, and on every row on a touch screen; Shift+F10 opens it from the keyboard. That is not hover-only. Nor is a selectable tree's checkbox, which shows on a row's icon under the pointer: Space selects the focused row, and the row's menu holds Select.
  • Nothing moves out from under a pointer that is still on it. A part whose place follows what it changes, a menu whose trigger the bar moves as its picks widen it or a picture whose zoom grows the dialog around its controls, stays put while the pointer is on it or near it, and moves once the pointer has gone, through usePointerHold. A menu the part opens is part of it until a choice there closes it, and the choice then shows at once. FilterMenu and the attachment viewer do this themselves.
  • Touch sizes for the toolbar icons
Do

Draw a row's action button all the time, ghost and icon-xs, so it is quiet but there for the keyboard and the thumb.

  • Touch sizes for the toolbar icons
Don't

Hide it until the row is hovered. Tab still lands on a button nobody can see, and a phone cannot hover at all. Hover over the row to find it.

Keyboard#

Every @orz/ui control is a native element or a Radix primitive, so the keys below work without code. What an app adds is the order: Tab follows reading order when the DOM does, so lay the page out in the DOM in the order it is read rather than reordering it with CSS.

KeyDoes
Tab, Shift+TabMoves to the next or previous control, with the focus ring showing where
EnterPresses a button, follows a link, submits a single-line field's form
SpacePresses a button, toggles a Switch or Checkbox, opens a Select
EscapeCloses the open overlay, a menu, a Popover, a Dialog, and returns focus to what opened it: its trigger, or the row or button that set it open
Arrow keysMove inside one control: a menu's items, Tabs, a RadioGroup, a Slider
Home, EndThe first and last item of a menu, a list box or the QueryBox suggestions
Shift+DeleteRemoves the highlighted past query from a QueryBox's history, as in a browser's address bar
A letterIn an open menu or Select, jumps to the first item that starts with it; in a submenu with a filter box, filters it
Indent with

Click in the example and put the mouse away. Tab stops at each switch, the select and the radio group, once each; Space or Enter flips a switch. Space opens the select, a letter jumps to a language (R for Rust), Home and End reach the ends of the list, and Escape closes it without a change. The arrow keys move the radio group's choice.

A group that the arrow keys move through, Tabs or a RadioGroup, is one Tab stop: Tab enters it at the selected item and the next Tab leaves it. Do not make every item a Tab stop, and do not remove the focus ring (Accessibility has the contrast it needs).

Focus where a person expects to type, and only there: a search page opens with its box focused, a dialog with its first field. On a phone that same focus raises the keyboard over the page, so an app that focuses something on arrival asks the pointer first:

tsx
import { POINTER_FINE, useMediaQuery } from "@orz/ui/hooks/use-media-query";

const fine = useMediaQuery(POINTER_FINE);
<Input autoFocus={fine} … />

Shortcuts#

A shortcut hurries an action that is already on screen. It is never the only way to an action, and it is shown where the action is: in the button's tooltip, or as DropdownMenuShortcut on the menu item.

  • / reaches search from anywhere on the page, through useSlashShortcut. It stands down while the focus is in a field, so typing a / still types one. An empty search box shows the key as a Kbd at its end, placed with top-sunken-centre as the box's glass is.
  • A single-character shortcut can be turned off. Speech input and a stray key press fire them by accident, so WCAG asks for a setting (2.1.4); wire it to useSlashShortcut's enabled. A shortcut with Ctrl or ⌘ needs no setting.
  • Use ⌘ on Apple platforms and Ctrl elsewhere, and show the glyph each platform uses: ⌘ ⌥ ⇧ on a Mac, Ctrl Alt Shift elsewhere. EditorShortcutsHelp in @orz/ui-codemirror already does both for an editor.
  • Leave the browser's and the system's keys alone. ⌘/Ctrl with T, W, N, L, R, Tab and the number keys belong to the browser; a tool that takes them strands people who reach for them.
  • List them. A tool with more than a handful of shortcuts shows them all in one place, a dialog opened from the help menu or with ?. Print each key as a Kbd, which a style may draw as a keycap or as the key's name alone. Beside an editor, EditorShortcutsHelp is that place: give it the words for the submit and cancel keys the editor binds (submit, cancel) and the keys the app binds itself (shortcuts), so it lists every key the editor answers to.
Do

Give the action people take over and over a shortcut, and print it next to the action's name so it is learned by using the tool. Hover over an icon to see it.

Touch sizes for the toolbar icons

Press E to archive.

Don't

Bind an action to a key with no button or menu item behind it: nobody finds it, and nobody on a phone can use it.

Pointer and width are two questions#

Width decides the layout; the pointer decides the room around the controls and what hover may do. A narrow desktop window is still clicked, a tablet is wide and still touched. Ask useMediaQuery(MD_UP) to lay out, and useMediaQuery(POINTER_FINE) only for behaviour that depends on a mouse and a keyboard being there, as the autofocus above does. Sizes need neither: the components make the room a coarse pointer needs by themselves (Touch & mobile).

POINTER_FINE asks about the primary pointer. A touchscreen laptop driven by its trackpad answers fine and keeps the desktop sizes, which is what the person using it is doing.

Dragging and right-click#

  • Anything that can be dragged can also be done without a drag: a menu item, a pair of move buttons, a field to type the value (WCAG 2.5.7). A list ordered by hand has both on every row, a handle and a pair of move buttons: Reordering.
  • A right-click menu, where an app has one, repeats the ⋯ menu; it adds no action of its own. Right-click does not exist on a phone and is not discoverable on a desk.

On each platform#

  • Pointer. All of the above. Controls are drawn at their compact sizes, and a mouse lands on a 24px target reliably (Density).
  • Touch. Nothing hovers, tooltips stay shut, and a keyboard, if any, is on screen and covers half of it. Touch & mobile has the rest.

In the demos