search

Search

Search input pattern for quick discovery.

Search Examples

Copy-ready examples with live previews.

Basic usage

Controlled open state and controlled input value.

Live preview

Controlled search surface. Focus the input to open, and use the close button to clear.

Basic search

import { useMemo, useState } from "react";
import Search from "@/packages/ui/src/_components/search/Search";
import Search_results from "@/packages/ui/src/_components/search/Search_results/Search_results";

const ITEMS = ["Alice", "Bob", "Charlie"];

export default function Example() {
  const [open, setOpen] = useState(false);
  const [value, setValue] = useState("");

  const filtered = useMemo(() => {
    const q = value.trim().toLowerCase();
    if (!q) return ITEMS;
    return ITEMS.filter((x) => x.toLowerCase().includes(q));
  }, [value]);

  return (
    <Search
      isView={open}
      onOpenChange={setOpen}
      value={value}
      onValueChange={setValue}
      placeholder="Search..."
      containerContent={
        <Search_results
          items={filtered}
          renderItem={(t) => <div>{t}</div>}
        />
      }
    />
  );
}

Layout + fit

Switch between layout presets and fit behavior.

When fit="full", the container must have an explicit height.

Live preview

layoutfit
Note: when fit="full", the container must have a fixed height.

layout + fit

import { useState } from "react";
import Search from "@/packages/ui/src/_components/search/Search";

export default function Example() {
  const [open, setOpen] = useState(true);
  const [value, setValue] = useState("ren");

  return (
    <div style={{ height: 520 }}>
      <Search
        isView={open}
        onOpenChange={setOpen}
        value={value}
        onValueChange={setValue}
        layout="docked"
        fit="full"
      />
    </div>
  );
}

Search_results

Standalone results list: divider + stackVariants + custom renderItem.

Live preview

stackVariants
Yoo, Haneul
Eli, me
Zita, Odette, Dagmar
In, Aki
Renée Claes

Results list

import Search_results from "@/packages/ui/src/_components/search/Search_results/Search_results";

export default function Example() {
  return (
    <Search_results
      items={["Alpha", "Beta", "Gamma"]}
      divider
      stackVariants="dense"
      renderItem={(t) => <div>{t}</div>}
      emptyContent={<div style={{ padding: 16 }}>No results</div>}
    />
  );
}

Disabled

Disable the whole surface (input + interactions).

Live preview

disabled

import Search from "@/packages/ui/src/_components/search/Search";

export default function Example() {
  return (
    <Search
      isView
      disabled
      value="search"
      onValueChange={() => {}}
      onOpenChange={() => {}}
    />
  );
}

Interactive playground

A richer stage to validate combinations inside the live preview container.

Live preview

Tip: fit="full" requires the stage to have an explicit height.
Quick presets:
layout
fit
stackVariants

Playground

import { useMemo, useState } from "react";
import Search from "@/packages/ui/src/_components/search/Search";
import Search_results from "@/packages/ui/src/_components/search/Search_results/Search_results";

const ITEMS = ["Alice", "Bob", "Charlie"];

export default function Example() {
  const [open, setOpen] = useState(false);
  const [value, setValue] = useState("");

  const filtered = useMemo(() => {
    const q = value.trim().toLowerCase();
    if (!q) return ITEMS;
    return ITEMS.filter((x) => x.toLowerCase().includes(q));
  }, [value]);

  return (
    <div style={{ height: 520 }}>
      <Search
        isView={open}
        onOpenChange={setOpen}
        value={value}
        onValueChange={setValue}
        containerContent={
          <Search_results items={filtered} renderItem={(t) => <div>{t}</div>} />
        }
      />
    </div>
  );
}

On this page

Search Props

Search — Props
PropTypeRequiredDefaultDescription
isViewbooleanYesControlled state: true shows the expanded search view, false shows the collapsed view.
onOpenChange(nextOpen: boolean) => voidYesCalled when the component requests an open-state change (e.g. focus opens, ESC closes, clear/back buttons).
valuestringYesControlled input value.
onValueChange(nextValue: string) => voidYesCalled on every input change. Use it to keep the controlled value in sync.
placeholderstringNo"Search..."Input placeholder.
disabledbooleanNofalseDisables user interaction (input + triggers).
layout"default" | "docked"No"default"Layout preset. Use docked when the search is visually attached to another surface (e.g. a top app bar).
fit"auto" | "full"No"auto"Sizing behavior for the expanded content. When fit='full', the parent container must have an explicit height.
leadingContentReact.ReactNodeNoundefinedSlot rendered at the start of the input row (e.g. back/menu button).
trailingContentReact.ReactNodeNoundefinedSlot rendered at the end of the input row (e.g. clear button, avatar, mic).
containerContentReact.ReactNodeNoundefinedExpanded content (usually a <Search_results /> list).
onSubmit(value: string) => voidNoundefinedCalled when the user submits the search (e.g. pressing Enter).
inputPropsReact.InputHTMLAttributes<HTMLInputElement>NoundefinedForwarded props for the underlying <input> (id, name, autoComplete, etc.).
classNamestringNoundefinedOptional className for the root element.
customStylesReact.CSSPropertiesNoundefinedOptional inline styles for the root element.

Search_results Props

Search_results — Props
PropTypeRequiredDefaultDescription
itemsReadonlyArray<unknown>No[]Items to render. You control the UI of each row via renderItem.
renderItem(item: unknown, index: number) => React.ReactNodeYesRow renderer. Return the content of a single result row (text + actions, etc.).
stackVariants"dense" | "normal" | "spacious"No"dense"Spacing preset applied to the internal Stack wrapper for each row.
dividerbooleanNotrueWhen true, renders a divider between rows.
emptyContentReact.ReactNodeNoundefinedRendered when items is empty.
rowClassNamestringNoundefinedOptional className applied to each row container.
classNamestringNoundefinedOptional className for the root element.
customStylesReact.CSSPropertiesNoundefinedOptional inline styles for the root element.