Skip to content

Morphing Command Nav

A floating nav pill that grows into a command palette in place: the same surface morphs from pill to panel, results are grouped with a light that slides between them, and it shrinks back on Escape or a pick.

ProDark Precisionminimalneon

This is a viberdy Pro component

The live preview, the props panel and the write-up are open to everyone. The full source, the AI prompt and CLI install are part of Pro.

Preview

Props

No runtime dependencies
"use client";

import { useEffect, useId, useMemo, useRef, useState, useSyncExternalStore } from "react";
import type { CSSProperties, KeyboardEvent as ReactKeyboardEvent } from "react";

/**
 * MorphingCommandNav — a nav pill that grows into a command palette.
 *
 * The same surface animates from a floating pill (brand, links, a search
 * button with a Cmd K keycap, sign in, a call to action) into a palette:
 * the links fade out, a search field fades in, and results are grouped
 * with a light that slides between them. Cmd/Ctrl + K, the search button,
 * Escape, a pick or a click outside open and close it; focus goes to the
 * field and back to the trigger. hotkey="focus" limits the shortcut to
 * when focus is inside, so a host page's own palette never opens too.
 *
 * Once measured, the shell floats over the page, so opening it never
 * pushes content down.

  // ---------------------------------------------------------------
  // Full source available with a viberdy Pro subscription.
  // https://viberdy.dev/pricing
  // ---------------------------------------------------------------
}
Notes

About this component

The kit's header, and its search. At rest it is a floating pill: the brand, links, a Search button with a Cmd K keycap, sign in and one white call to action, with a thread of light along its top edge. Press Cmd or Ctrl + K, or the Search button, and the pill itself grows into a 560px command palette: the surface animates its measured width, height and corner radius while the links fade out and the search field fades in, over a dimmed page. Results are grouped (pages, docs, actions) and filtered as you type; a light slides between them as you move with the arrow keys or the pointer, Enter opens one, and Escape, a click outside or a pick shrinks the palette back into the pill and returns focus to the trigger. Once measured, the pill floats over the page, so opening it never pushes content down. With hotkey set to focus the shortcut only works while focus is inside, for pages that already have a Cmd K of their own. onSelect lets you handle a command yourself, for example to scroll to a section.

Curator’s note

The Dark Precision kit's navigation (slot 5), cut from dark-precision-site. Pro as a stateful system (a measured shared-surface morph, a combobox with grouped results, keyboard and focus management), which keeps the kit at 6/6.

Related

Pairs well with

Matched on shared tags and category — the entries most likely to be used alongside this one.

Pro

A Cmd+K menu with real submenu drilling, a breadcrumb trail, and scoped per-level search.

command menucmdknavigation
Pro

A recursive, collapsible file tree with real roving-tabindex arrow-key navigation.

treefile explorersidebar

Site navigation as one row of bento tiles sharing 1px hairlines, with a pointer light that shows through them and menus that open as panels of tiles.

navigationnavbarmega menu