HextaUI

Command: Pages

An item with page opens the matching <CommandPage />. The page title appears as a chip in the input, the list slides in from the side, and Backspace on an empty search or Escape goes back.

Nothing selected yet.

"use client"

import * as React from "react"
import {
  IconBrandGithub,
  IconFolder,
  IconFolderPlus,
  IconUsers,
} from "@tabler/icons-react"

import {
  Command,
  CommandEmpty,
  CommandGroup,
  CommandInput,
  CommandItem,
  CommandList,
  CommandPage,
} from "@/components/ui/command"

const projects = ["hextaui", "marketing-site", "design-tokens"]
const members = ["Ada Lovelace", "Grace Hopper", "Alan Turing"]

export function CommandPages() {
  const [last, setLast] = React.useState<string>()

  return (
    <div className="flex w-full max-w-sm flex-col gap-3">
      <Command>
        <CommandInput placeholder="Search…" />
        <CommandList>
          <CommandEmpty>No results found.</CommandEmpty>
          <CommandGroup heading="Workspace">
            <CommandItem page="projects" pageTitle="Projects">
              <IconFolder />
              Projects
            </CommandItem>
            <CommandItem page="members" pageTitle="Members">
              <IconUsers />
              Members
            </CommandItem>
            <CommandItem onSelect={() => setLast("New project")}>
              <IconFolderPlus />
              New project
            </CommandItem>
          </CommandGroup>
          <CommandPage id="projects">
            <CommandGroup heading="Projects">
              {projects.map((project) => (
                <CommandItem key={project} onSelect={setLast}>
                  <IconBrandGithub />
                  {project}
                </CommandItem>
              ))}
            </CommandGroup>
          </CommandPage>
          <CommandPage id="members">
            <CommandGroup heading="Members">
              {members.map((member) => (
                <CommandItem key={member} onSelect={setLast}>
                  <IconUsers />
                  {member}
                </CommandItem>
              ))}
            </CommandGroup>
          </CommandPage>
        </CommandList>
      </Command>
      <p className="text-sm text-muted-foreground">
        {last ? `Selected “${last}”.` : "Nothing selected yet."}
      </p>
    </div>
  )
}

This adds the example as components/examples/command/pages.tsx, together with the Command component and the HextaUI theme tokens it needs.

pnpm dlx shadcn@latest add https://hextaui.com/r/command-pages.json

To add only the component, follow the Command installation.

Props in this example

The Command props this example sets, from the API reference.

PropTypeDefault
placeholder
string–
PropTypeDefault
heading
ReactNode–
PropTypeDefault
onSelectRuns on click, Enter or the item’s shortcut, after the confirm blink.
(value: string) => void–
pageOpens the CommandPage with this id instead of running.
string–
pageTitleTitle shown in the page chip. Defaults to the value.
string–
PropTypeDefault
idMatches the page prop of the item that opens it. Its groups and items only render while it is the current page.
string–

Every prop is in the Command API reference.

See them all, with keyboard support and accessibility notes, on the Command page.