# Desktop & pointer

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

API [Tooltip](/ui/storybook/?path=/docs/ui-primitives-tooltip--docs) [Kbd](/ui/storybook/?path=/docs/ui-primitives-kbd--docs) [HoverCard](/ui/storybook/?path=/docs/ui-primitives-hovercard--docs) [DropdownMenu](/ui/storybook/?path=/docs/ui-primitives-dropdownmenu--docs) [Select](/ui/storybook/?path=/docs/ui-primitives-select--docs) [Switch](/ui/storybook/?path=/docs/ui-primitives-switch--docs) [RadioGroup](/ui/storybook/?path=/docs/ui-primitives-radiogroup--docs) [Toaster](/ui/storybook/?path=/docs/ui-primitives-toaster--docs) [Reorder](/ui/storybook/?path=/docs/ui-reorder--docs) [useSlashShortcut](/ui/storybook/?path=/docs/ui-hooks-useslashshortcut--docs) [usePointerHold](/ui/storybook/?path=/docs/ui-hooks-usepointerhold--docs) [useMediaQuery](/ui/storybook/?path=/docs/ui-hooks-usemediaquery--docs) [EditorShortcutsHelp](/ui/storybook/?path=/docs/ui-codemirror-editorshortcutshelp--docs)

**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.

```tsx
import { INBOX_PEOPLE, INBOX_THREADS } from "@orz/fixtures/inbox.ts";
import { Button } from "@orz/ui/components/button";
import {
  DropdownMenu,
  DropdownMenuContent,
  DropdownMenuItem,
  DropdownMenuSeparator,
  DropdownMenuShortcut,
  DropdownMenuTrigger,
} from "@orz/ui/components/dropdown-menu";
import { EmptyState } from "@orz/ui/components/empty-state";
import { Frame } from "@orz/ui/components/frame";
import { Kbd } from "@orz/ui/components/kbd";
import { List, ListItem } from "@orz/ui/components/list";
import { Pane } from "@orz/ui/components/pane";
import { ToolbarButton } from "@orz/ui/components/toolbar";
import {
  Tooltip,
  TooltipContent,
  TooltipProvider,
  TooltipTrigger,
} from "@orz/ui/components/tooltip";
import {
  ArchiveIcon,
  EllipsisIcon,
  LinkIcon,
  MailIcon,
  RefreshCwIcon,
  SquarePenIcon,
  Trash2Icon,
} from "lucide-react";
import { useState } from "react";
import { toast } from "sonner";

const THREADS = INBOX_THREADS.filter(({ folder }) => folder === undefined)
  .slice(0, 3)
  .map(({ id, subject, messages }) => ({
    id,
    subject,
    from: INBOX_PEOPLE[messages[0]?.from ?? ""],
  }));

type Thread = (typeof THREADS)[number];

export function ThreadList() {
  const [threads, setThreads] = useState(THREADS);
  const remove = (thread: Thread, message: string) => {
    setThreads((now) => now.filter((each) => each !== thread));
    toast(message, {
      action: {
        label: "Undo",
        onClick: () =>
          setThreads((now) =>
            THREADS.filter((each) => each === thread || now.includes(each)),
          ),
      },
    });
  };
  return (
    <TooltipProvider>
      <Frame asChild>
        <Pane purpose="panel">
          <Pane
            purpose="toolbar"
            edge="bottom"
            className="flex items-center gap-1 px-3 py-1.5"
          >
            <span className="flex-1 font-medium text-ui">Inbox</span>
            <Tooltip>
              <TooltipTrigger asChild>
                <ToolbarButton
                  size="icon-sm"
                  aria-label="Refresh"
                  onClick={() => toast("Inbox up to date")}
                >
                  <RefreshCwIcon />
                </ToolbarButton>
              </TooltipTrigger>
              <TooltipContent>Refresh</TooltipContent>
            </Tooltip>
            <Tooltip>
              <TooltipTrigger asChild>
                <ToolbarButton
                  size="sm"
                  onClick={() => toast("New message started")}
                >
                  <SquarePenIcon />
                  Compose
                </ToolbarButton>
              </TooltipTrigger>
              <TooltipContent>
                Compose <Kbd>C</Kbd>
              </TooltipContent>
            </Tooltip>
          </Pane>
          <List purpose="collection">
            {threads.length > 0 ? (
              <ul>
                {threads.map((thread) => (
                  <ListItem key={thread.id} asChild>
                    <li className="flex min-h-row items-center gap-2 px-3 text-ui touch:min-h-touch">
                      <span className="w-20 shrink-0 truncate font-medium">
                        {thread.from}
                      </span>
                      <span className="min-w-0 flex-1 truncate text-muted-foreground">
                        {thread.subject}
                      </span>
                      <DropdownMenu>
                        <DropdownMenuTrigger asChild>
                          <Button
                            variant="ghost"
                            size="icon-xs"
                            aria-label={`More actions for “${thread.subject}”`}
                          >
                            <EllipsisIcon />
                          </Button>
                        </DropdownMenuTrigger>
                        <DropdownMenuContent align="end" className="w-52">
                          <DropdownMenuItem
                            onSelect={() =>
                              remove(thread, "Conversation archived")
                            }
                          >
                            <ArchiveIcon />
                            Archive
                            <DropdownMenuShortcut>E</DropdownMenuShortcut>
                          </DropdownMenuItem>
                          <DropdownMenuItem
                            onSelect={() =>
                              remove(thread, "Conversation moved to Trash")
                            }
                          >
                            <Trash2Icon />
                            Delete
                            <DropdownMenuShortcut>#</DropdownMenuShortcut>
                          </DropdownMenuItem>
                          <DropdownMenuItem
                            onSelect={() =>
                              toast("Conversation marked as unread")
                            }
                          >
                            <MailIcon />
                            Mark as unread
                            <DropdownMenuShortcut>Shift U</DropdownMenuShortcut>
                          </DropdownMenuItem>
                          <DropdownMenuSeparator />
                          <DropdownMenuItem
                            onSelect={() => toast("Link copied")}
                          >
                            <LinkIcon />
                            Copy link
                          </DropdownMenuItem>
                        </DropdownMenuContent>
                      </DropdownMenu>
                    </li>
                  </ListItem>
                ))}
              </ul>
            ) : (
              <EmptyState title="Nothing in Inbox" className="py-6" />
            )}
          </List>
        </Pane>
      </Frame>
    </TooltipProvider>
  );
}
```

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.

**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.

**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.

| Key            | Does                                                                                                                                              |
| -------------- | ------------------------------------------------------------------------------------------------------------------------------------------------- |
| Tab, Shift+Tab | Moves to the next or previous control, with the focus ring showing where                                                                          |
| Enter          | Presses a button, follows a link, submits a single-line field's form                                                                              |
| Space          | Presses a button, toggles a `Switch` or `Checkbox`, opens a `Select`                                                                              |
| Escape         | Closes 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 keys     | Move inside one control: a menu's items, `Tabs`, a `RadioGroup`, a `Slider`                                                                       |
| Home, End      | The first and last item of a menu, a list box or the `QueryBox` suggestions                                                                       |
| Shift+Delete   | Removes the highlighted past query from a `QueryBox`'s history, as in a browser's address bar                                                     |
| A letter       | In an open menu or `Select`, jumps to the first item that starts with it; in a submenu with a filter box, filters it                              |

```tsx
import { LANGUAGES } from "@orz/fixtures/account.ts";
import { GroupHeading } from "@orz/ui/components/group-heading";
import { Label } from "@orz/ui/components/label";
import { RadioGroup, RadioGroupItem } from "@orz/ui/components/radio-group";
import {
  Select,
  SelectContent,
  SelectItem,
  SelectTrigger,
  SelectValue,
} from "@orz/ui/components/select";
import { Switch } from "@orz/ui/components/switch";

const INDENTS = [
  { value: "2", label: "2 spaces" },
  { value: "4", label: "4 spaces" },
  { value: "tab", label: "Tabs" },
];

export function EditorSettings() {
  return (
    <div className="grid max-w-md gap-4">
      <div className="flex items-center justify-between gap-4 touch:min-h-touch">
        <Label htmlFor="keys-wrap">Wrap long lines</Label>
        <Switch id="keys-wrap" defaultChecked />
      </div>
      <div className="flex items-center justify-between gap-4 touch:min-h-touch">
        <Label htmlFor="keys-line-numbers">Show line numbers</Label>
        <Switch id="keys-line-numbers" defaultChecked />
      </div>
      <div className="flex items-center justify-between gap-4 touch:min-h-touch">
        <Label htmlFor="keys-language">New files open as</Label>
        <Select defaultValue="markdown">
          <SelectTrigger id="keys-language" className="w-36">
            <SelectValue />
          </SelectTrigger>
          <SelectContent>
            {LANGUAGES.map(({ value, label }) => (
              <SelectItem key={value} value={value}>
                {label}
              </SelectItem>
            ))}
          </SelectContent>
        </Select>
      </div>
      <div className="grid gap-2">
        <GroupHeading id="keys-indent">Indent with</GroupHeading>
        <RadioGroup aria-labelledby="keys-indent" defaultValue="2">
          {INDENTS.map(({ value, label }) => (
            <div key={value} className="flex items-center gap-2">
              <RadioGroupItem value={value} id={`keys-indent-${value}`} />
              <Label htmlFor={`keys-indent-${value}`}>{label}</Label>
            </div>
          ))}
        </RadioGroup>
      </div>
    </div>
  );
}
```

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](/ui/guidelines/content/accessibility/index.md) 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](https://www.w3.org/WAI/WCAG22/Understanding/character-key-shortcuts.html)); 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.

**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](/ui/guidelines/platforms/touch-and-mobile/index.md)).

`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](https://www.w3.org/WAI/WCAG22/Understanding/dragging-movements.html)). A list ordered by hand has both on every row, a handle and a pair of move buttons: [Reordering](/ui/guidelines/patterns/reordering/index.md).
- 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](/ui/guidelines/foundations/density/index.md)).
- **Touch.** Nothing hovers, tooltips stay shut, and a keyboard, if any, is on screen and covers half of it. [Touch & mobile](/ui/guidelines/platforms/touch-and-mobile/index.md) has the rest.

## In the demos

- [Tasks](/ui/demos/tasks/index.md): The ⋯ on a row and on a card never waits for hover, a task's title, on the board too, is a link that opens in a new tab, and the HoverCard on an assignee only repeats what the Assignee filter offers.
- [Mail](/ui/demos/mail/index.md): Press ? for every shortcut, and turn them off in the same dialog. A toolbar button's tooltip prints its key, so e for Archive is learned where Archive is. j and k walk the list.
- [Notes](/ui/demos/notes/index.md): Type / at the start of a line for blocks, or # for the tags already in use. The keyboard button lists the editor's shortcuts with each platform's keys.
- [Pull request](/ui/demos/pull-request/index.md): Tab stops once at each of the pull request's pages, each job and each Details, and Enter follows the link or presses the button.
- [Config editor](/ui/demos/config-editor/index.md): ⌘ or Ctrl and S saves the file, and the Save button carries the same keys in aria-keyshortcuts, so a screen reader announces them.
- [Binary inspector](/ui/demos/binary-inspector/index.md): Drop a file anywhere to open it: a shortcut for Open file…, which does the same without a drag. Undo and Redo name themselves in a tooltip.
