Omnibar

The header's search field, grown in place into scoped results with each row's actions inline. On a phone it becomes a full-screen search.

Source
$npx @dinachi/cli@latest add omnibar

label
OmnibarScopes
recent
shortcut
disabled

Usage

import { BedDouble, User } from "lucide-react"
import {
  Omnibar,
  OmnibarContent,
  OmnibarInput,
  OmnibarList,
  OmnibarScopes,
  OmnibarTrigger,
  type CommandItem,
  type OmnibarScope,
} from "@/components/ui/omnibar"

const commands: CommandItem[] = [
  {
    id: "tomas",
    label: "Tomás Herrera",
    description: "Arriving 14:00",
    group: "Guests",
    icon: <User />,
    actions: [
      { id: "check-in", label: "Check in" },
      { id: "message", label: "Message" },
    ],
  },
  { id: "room-108", label: "Room 108", description: "Garden Single", group: "Rooms", icon: <BedDouble /> },
]

const scopes: OmnibarScope[] = [
  { id: "guests", label: "Guests", prefix: "@" },
  { id: "rooms", label: "Rooms", prefix: "#" },
]

export function DeskSearch({ run }: { run: (id: string, action?: string) => void }) {
  return (
    <Omnibar items={commands} scopes={scopes} onRun={(item, action) => run(item.id, action?.id)}>
      <OmnibarTrigger />
      <OmnibarContent>
        <OmnibarInput />
        <OmnibarScopes />
        <OmnibarList />
      </OmnibarContent>
    </Omnibar>
  )
}

Examples

Front desk

Saltmarsh Hotel · Mon 14 Dec

A hotel front desk's header search. Type @, # or > to scope it, or pick a chip; Tab moves through the highlighted row's actions. On a phone it becomes a full-screen search.
import { BedDouble, FileText, User, Zap } from 'lucide-react';
import {
  Omnibar,
  OmnibarContent,
  OmnibarInput,
  OmnibarList,
  OmnibarScopes,
  OmnibarTrigger,
  type CommandItem,
  type OmnibarScope,
} from '@/components/ui/omnibar';

const guest = [
  { id: 'check-in', label: 'Check in' },
  { id: 'assign', label: 'Assign room' },
  { id: 'message', label: 'Message' },
];

const commands: CommandItem[] = [
  { id: 'arrivals', label: 'Arrivals', group: 'Pages', icon: <FileText />, shortcut: 'G A' },
  { id: 'check-in', label: 'Check in a guest', group: 'Actions', icon: <Zap />, shortcut: 'C' },
  { id: 'tomas', label: 'Tomás Herrera', description: 'Arriving 14:00', group: 'Guests', icon: <User />, actions: guest },
  { id: 'ada', label: 'Ada Okafor', description: 'Arriving 15:30', group: 'Guests', icon: <User />, actions: guest },
  { id: 'room-108', label: 'Room 108', description: 'Garden Single', group: 'Rooms', icon: <BedDouble /> },
];

const scopes: OmnibarScope[] = [
  { id: 'actions', label: 'Actions', prefix: '>' },
  { id: 'guests', label: 'Guests', prefix: '@' },
  { id: 'rooms', label: 'Rooms', prefix: '#' },
];

export function Search({ onRun }: { onRun: (item: CommandItem, actionId?: string) => void }) {
  return (
    <Omnibar items={commands} scopes={scopes} recent={['tomas']} onRun={(item, action) => onRun(item, action?.id)}>
      <OmnibarTrigger placeholder="Search guests, rooms, bookings" />
      <OmnibarContent>
        <OmnibarInput />
        <OmnibarScopes />
        <OmnibarList />
      </OmnibarContent>
    </Omnibar>
  );
}

Notes

Scopes

A scope narrows the list to one kind of record. Pick it from its chip, or type its prefix first: @tom searches guests for tom. A prefix only works from All, so a scoped search can hold an @. Backspace on an empty search goes back to All. By default a scope holds the items whose group is its label; give it match when the groups do not line up.

Actions on the row

The highlighted row shows its actions when it has more than one. Tab and Shift+Tab move between them, Enter runs the one picked, and a click runs the one clicked. Moving the highlight or typing starts again from the first. A row with one action, or none, leaves Tab alone. Disabled rows show no actions and are listed last, so the first highlight is always one Enter can run.

Long lists

The list renders at most limit rows, 50 by default, so a search over thousands of records stays quick: keep typing to narrow it. Moving the highlight re-renders only the two rows it leaves and lands on, and rows are memoized, so a custom OmnibarList child that returns an OmnibarItem keeps that.

The item shape

CommandItem, CommandAction, CommandRunDetails and filterCommands live in command-items, which dinachi add omnibar installs alongside, and the Command Palette uses the same module, so one list can feed both. A sub-list's items are listed in its place here, as the omnibar has no levels.

No motion

It is used many times a day, so it never animates: the field does not grow, the panel does not fade in, and the results, highlight and scope change at once. On a phone the action sheet is a Drawer and keeps its own slide.

On a phone

Below 640px the field opens a full-screen search with Cancel, and chips without prefixes. The best match carries its actions as buttons; other rows have a ⋯ that opens them in a sheet. Rows, chips, the ⋯ menus, buttons and Cancel take a tap of 44px or more, the sheet's actions 50px. Give OmnibarInput a phonePlaceholder when its placeholder is long.

API

items
agent
CommandItem[]
Every command, in the order groups and rows are listed. The same shape as the Command Palette's. The agent reads them while closed.
scopesOmnibarScope[]
The chips after All. Each holds the items whose group is its label, or what its match function picks; a prefix such as @ picks it by typing.
recentstring[]
Ids listed first, under Recent, while the search is empty and no scope is picked.
recentLabelstring = "Recent"
The heading over recent items.
suggestedstring[]
Ids listed after Recent while the search is empty and no scope is picked, such as the main actions. Without it, the items after Recent.
idleLimitnumber = 8
How many rows show while the search is empty. Applies once recent or suggested is set; without either, the list shows up to limit.
limitnumber = 50
The most rows the list renders, searching or idle. The count read out says how many matched in all, and an agent's search returns the same rows people see.
onRun
agent
(item, action, details) => void
Runs a picked item with the action chosen, or its first. details.cancel() keeps it open.
openboolean
Controlled open state.
defaultOpenboolean = false
Starts open when uncontrolled.
onOpenChange
agent
(open, details) => void
Runs for people and agents. details.cancel() refuses the change.
valuestring
Controlled search text, without the scope's prefix.
defaultValuestring = ""
Starting search text.
onValueChange
agent
(value, details) => void
Runs as the search changes, from either side.
scopestring | null
Controlled scope id. null is All.
defaultScopestring | null = null
Starting scope when uncontrolled.
onScopeChange(scope) => void
Runs when a chip, a prefix, Backspace or an agent changes the scope.
shortcutstring | false = "/"
The key that focuses it from the page. Ignored while typing in another field. "mod+j" asks for Cmd or Ctrl and works anywhere. false turns it off.
label
agent
string = "Search"
Names the field and the panel. The agent finds the omnibar by it.
filter(item, query) => boolean = filterCommands
Decides what matches. The default needs every word in the label, description or keywords.
disabled
agent
boolean = false
Blocks the field, the shortcut and the agent.

Agent

Inside an AgentProvider, it appears in agent.snapshot() as combobox.

Reads

label

The omnibar's label.

open

True while the panel is showing.

value

The search text, with the scope's prefix in front, while open.

items

Every command while closed, or the matches while open.

disabled

True when the omnibar is blocked.

Actions

open() / close()

Opens or closes the panel.

search("tom", "Guests")

Opens it, picks the scope if named, types the text and returns the matches with their group and actions. A prefix in the text picks its scope too.

select("Tomás Herrera", "Check in")

Runs a command with its first action or the one named, and closes.

Opening and closing run through onOpenChange, the search through onValueChange and running through onRun. isAgentChange(details) is true for each; details.cancel() refuses it and the agent is told. disabled refuses everything. The agent finds a closed omnibar through its field, so render OmnibarTrigger.

await agent.act({
  steps: [
    { ref: "Search the desk", action: "search", args: ["tom", "Guests"] },
    { ref: "Search the desk", action: "select", args: ["Tomás Herrera", "Check in"] },
  ],
})

Accessibility

  • The field is a button named by label while closed; the panel is a popover dialog with the same name, and focus moves to its search and back to the field on close.
  • The search has role combobox and the results are a listbox named by label; aria-activedescendant keeps focus in the search and the highlighted option is aria-selected.
  • Scope chips are toggle buttons in a group named Scope; the picked one is aria-pressed.
  • The listbox holds only options. Their actions are pointer targets hidden from assistive tech; the highlighted option is described by what Enter runs, such as Enter: Message, and moving it with Tab is announced politely, on a phone too.
  • Matched words are marked with mark. The number of matches and a scope picked by a typed prefix or Backspace are announced politely; a chip's aria-pressed speaks for itself. Moving the highlight clears the last announcement, so the same text speaks again on the next row.
  • On a phone the panel is modal: it has aria-modal and the rest of the page, bar live regions such as toasts, is hidden from assistive tech while it is up. The top hit's buttons and each ⋯ are touch targets inside the listbox, so a screen reader reaches the same sheets through buttons after it named Actions for and the item. The sheet is a Drawer named by the item that returns focus to the button that opened it.