Fusion UI LogoFusion UI Logo
Fusion UI LogoFusion UI Logo
/
Getting Started
Concepts
Components
Example Apps
Getting Started
Concepts
Components
Example Apps
Fusion UI LogoFusion UI Logo
Getting Started
Concepts
Components
Example Apps
Overview
Actions
Button
Button Group
Segmented Button
Deprecated
Split Button
Toggle Button
Click To Copy
Toolbar
Navigation
Main Nav
Side Menu
Page Header
Tabs
Breadcrumbs
On-Page Menu
Link
Command Menu
Application Switcher
Context Switcher
Account Menu
Menu Bar
Deprecated
Inputs & Forms
Form
Form Actions
Deprecated
Form Divider
Form Field
Form Repeat
Form Spacing
Input
Prefix & Suffix
Rich Text Input
Autocomplete
Select
Date / Time Input
Calendar
Slider
Selection
Checkbox
Radio
Switch
Switch Select
Chip
Chip Choice
Chip Filter
Chip Input
Chip Sortable
Visual Select
Pricing Plan Select
Feedback & Loading
Banner
Inline Message
Snackbar
Inline Snackbar
Loading Spinner
Skeleton
Text Skeleton
Contextual Information
Badge
Status
Tag
Tooltip
Info
Hotkey
Icon
Icon Sizer
Containers & Overlays
Tile
Tile Content
Tile Footer
Tile Header
Annotated Section
Modal
Sheet
Popover
Context Menu
Data Display
Data Table
List
Timeline
Data Visualization
KPI Card
Ratio Card
Bar Chart
Line Chart
Pie Chart
Heatmap Calendar
Layout
Container
Stack Layout
Flow Layout
Internals
Blanket
Expansion Panel
Menu List Base
Menu Group
Search Bar
Components
...
Command Menu

Command Menu

Keyboard first search for pages and actions, opened with ⌘K.

Overview

The CommandMenu lets people jump to pages and run commands from the keyboard. Components anywhere in the app register their commands; the menu searches them fuzzily. Try it in this documentation with ⌘K or Ctrl+K.

"use client";
import {CommandMenuTrigger, IconPlane, useCommandMenu} from "@brynlabs/fusion-ui";
import React, {useEffect} from "react";
export const CommandMenuExample = () => {
const {registerCommands} = useCommandMenu();
useEffect(
() =>
registerCommands([
{
title: "Test",
category: "Test",
callback: () => {
console.log("Test");
},
subtitle: "Test",
icon: <IconPlane />,
},
{
title: "Test 2",
category: "Test 2",
callback: () => {
console.log("Test 2");
},
subtitle: "Test",
icon: <IconPlane />,
},
{
title: "Test 3",
category: "Test",
callback: () => {
console.log("Test 3");
},
subtitle: "Test",
icon: <IconPlane />,
},
{
title: "Test 4",
category: "Test 2",
callback: () => {
console.log("Test 4");
},
subtitle: "Test",
icon: <IconPlane />,
},
]),
[registerCommands],
);
return <CommandMenuTrigger />;
};

External search

For results searched elsewhere, e.g. on a server, read the typed text from useCommandMenu().query and register the results with filter: false. They skip the fuzzy search and appear in the order they were registered, after the other commands. setLoading shows a spinner in the search field, overline adds a small line above the title and an id keeps an entry selected while results arrive.

"use client";
import {CommandMenuTrigger, IconSearch, useCommandMenu} from "@brynlabs/fusion-ui";
import React, {useEffect, useState} from "react";
const RECORDS = [
{id: "1", title: "Website relaunch", client: "Acme Corp", type: "Project"},
{id: "2", title: "Write invoice template", client: "Acme Corp › Website relaunch", type: "Task"},
{id: "3", title: "Acme Corp", client: "Berlin", type: "Customer"},
];
/**
* Results searched outside the menu (here: a fake server call) are registered with
* `filter: false`, so the menu shows them as they are ranked instead of fuzzy-filtering them.
*/
export const CommandMenuSearchExample = () => {
const {registerCommands, query, setLoading} = useCommandMenu();
const [results, setResults] = useState<typeof RECORDS>([]);
useEffect(() => {
if (!query.trim()) return;
setLoading(true);
const timeout = setTimeout(() => {
const needle = query.toLowerCase();
setResults(RECORDS.filter(record => record.title.toLowerCase().includes(needle)));
setLoading(false);
}, 300);
return () => {
clearTimeout(timeout);
setLoading(false);
};
}, [query, setLoading]);
useEffect(
() =>
registerCommands(
(query.trim() ? results : []).map(record => ({
id: record.id,
title: record.title,
overline: record.client,
subtitle: record.type,
category: "Search results",
filter: false,
icon: <IconSearch />,
callback: () => console.log(record.title),
})),
),
[query, results, registerCommands],
);
return <CommandMenuTrigger />;
};