Skip to content

Search Input

Search field with leading icon, “/” keycap hint that focuses the field, clear button (Escape clears too) and a loading spinner state. Two sizes, controlled or uncontrolled.

minimal/ui/search-input
Open ↗

Source

"use client";

import { useEffect, useId, useRef, useState, type InputHTMLAttributes } from "react";
import { Loader2, Search, X } from "lucide-react";
import { cn } from "@/lib/utils";

export interface SearchInputProps extends Omit<InputHTMLAttributes<HTMLInputElement>, "value" | "defaultValue" | "onChange" | "size"> {
  label?: string;
  value?: string;
  defaultValue?: string;
  onValueChange?: (value: string) => void;
  /** Show a spinner in place of the clear button. */
  loading?: boolean;
  /** Focus the field with "/" (ignored while typing elsewhere). */
  slashShortcut?: boolean;
  size?: "sm" | "md";
}

/** Search field with leading icon, “/” focus shortcut hint, clear button (Escape clears too) and loading state. */
export function SearchInput({
  label = "Search incidents",
  placeholder = "Search incidents, services, people…",
  value,
  defaultValue = "",
  onValueChange,
  loading = false,
  slashShortcut = true,
  size = "md",
  className,
  ...rest
}: SearchInputProps) {
  const id = useId();
  const ref = useRef<HTMLInputElement>(null);
  const [inner, setInner] = useState(defaultValue);
  const current = value ?? inner;
  const set = (v: string) => {
    setInner(v);
    onValueChange?.(v);
  };

  useEffect(() => {
    if (!slashShortcut) return;
    const onKey = (e: KeyboardEvent) => {
      const t = e.target as HTMLElement | null;
      if (e.key !== "/" || (t && (t.isContentEditable || ["INPUT", "TEXTAREA", "SELECT"].includes(t.tagName)))) return;
      e.preventDefault();
      ref.current?.focus();
    };
    window.addEventListener("keydown", onKey);
    return () => window.removeEventListener("keydown", onKey);
  }, [slashShortcut]);

  return (
    <div className={cn("relative", className)}>
      <label htmlFor={id} className="sr-only">
        {label}
      </label>
      <Search
        aria-hidden
        className={cn("pointer-events-none absolute top-1/2 left-3 -translate-y-1/2 text-da-muted-fg", size === "sm" ? "size-3.5" : "size-4")}
      />
      <input
        ref={ref}
        id={id}
        type="search"
        autoComplete="off"
        {...rest}
        value={current}
        onChange={(e) => set(e.target.value)}
        onKeyDown={(e) => {
          if (e.key === "Escape" && current) {
            e.preventDefault();
            set("");
          }
          rest.onKeyDown?.(e);
        }}
        placeholder={placeholder}
        className={cn(
          "peer da-focus da-transition w-full rounded-da-md border border-da-border bg-da-input pr-9 text-da-fg placeholder:text-da-muted-fg hover:border-da-border-strong [&::-webkit-search-cancel-button]:hidden",
          size === "sm" ? "h-8 pl-8 text-[13px]" : "h-9 pl-9 text-sm",
        )}
      />
      <span className="absolute top-1/2 right-2 flex -translate-y-1/2 items-center">
        {loading ? (
          <Loader2 aria-label="Searching" className="size-4 animate-spin text-da-muted-fg motion-reduce:animate-none" />
        ) : current ? (
          <button
            type="button"
            onClick={() => {
              set("");
              ref.current?.focus();
            }}
            aria-label="Clear search"
            className="da-focus grid size-5 place-items-center rounded-da-sm text-da-muted-fg hover:bg-da-muted hover:text-da-fg"
          >
            <X aria-hidden className="size-3.5" />
          </button>
        ) : (
          slashShortcut && (
            <kbd aria-hidden className="rounded-[4px] px-1.5 font-da-mono text-[11px] text-da-muted-fg ring-1 ring-da-border peer-focus:hidden">
              /
            </kbd>
          )
        )}
      </span>
    </div>
  );
}

export default SearchInput;

modules/minimal/ui/search-input/index.tsx

Props

PropTypeDefaultDescription
labelstring"Search incidents"Accessible label (visually hidden).
value / defaultValuestring—Value.
onValueChange(value: string) => void—Change handler.
loadingbooleanfalseSpinner.
slashShortcutbooleantrueFocus with /.
size"sm" | "md""md"Height.

Other input variants in Minimal

Input in other art directions

Input

Labelled text field with hint, error state, leading icon, suffix slot and two sizes. The field presses into its shadow on focus; errors switch to a red stroke with an explicit message.

BrutalistInput

Number Stepper

Numeric input flanked by chunky yellow − / + buttons (disabled at bounds), big display-font value, optional unit suffix; clamps typed values to min/max.

BrutalistInput

OTP Input

One-time-code input: ruled digit squares (split 3+3 for six digits) that turn yellow and press in on focus; auto-advance, backspace and arrow navigation, paste of the full code, completion callback and error state.

BrutalistInput

Textarea

Labelled multi-line field with a live character counter chip that turns orange near the limit, hint and error states; presses into its shadow on focus.

BrutalistInput

Combobox

Autocomplete select: a glass pill input that filters a frosted listbox as you type, with arrow-key highlight, Enter to choose, Escape to close, hints and a check on the selection.

GlassInput

Input

Frosted text field with label, hint, error state, leading icon, trailing slot (button, kbd, unit), rounded or pill shape and two sizes. Focus brightens the glass and adds a soft violet halo.

GlassInput

Range Slider

Glass slider on Radix Slider: frosted track, primary→accent range, glowing gradient thumbs with value bubbles on hover/focus and tick labels; single value or range.

GlassInput

Tag Input

Glass chip input: type and press Enter or comma to add gradient chips, Backspace removes the last, × removes one; quick-add suggestion chips and a max counter.

GlassInput

Checkbox Group

Settings checkboxes as ruled rows: square ink check boxes (native inputs), label and muted description; the whole row is clickable.

Mono CleanInput

Input

Underline field: mono uppercase label, a borderless input on a single bottom hairline that turns ink (2px) on focus, optional prefix, hint or red error.

Mono CleanInput

Search Input

Search field with live results: hairline-bordered input with icon and ⌘K hint; matches appear in a ruled list below with the query highlighted and a mono kind label; empty state included.

Mono CleanInput

Select Field

Native select styled as an underline field with a mono label and a custom chevron — reliable on every device and screen reader.

Mono CleanInput

Currency Input

Amount field with currency symbol prefix and an attached currency select; formats with thousands separators on blur, right-aligned mono digits.

Neo CorporateInput

File Upload

Receipt/document dropzone: dashed bordered area with upload icon, click-or-drag, file list with size, per-file size validation errors and remove buttons.

Neo CorporateInput

Input

Form field: label (with optional marker), bordered 40px input with leading/trailing adornments, blue focus ring, hint text or red error with aria-invalid.

Neo CorporateInput

Select Field

Labelled Radix Select styled as a bordered field: grouped options (e.g. GL accounts) with group headings, check on the selected item, portalled popover with data-da.

Neo CorporateInput

Chip Select

Multi-select as soft pill checkboxes: unselected sand pills, selected sage pills with a check that pops in; native checkboxes in a fieldset.

Organic SoftInput

Input

Soft filled text field: rounded sand-filled input that turns cream with a sage ring on focus, optional leading icon and trailing unit, hint or gentle clay error message.

Organic SoftInput

Target Slider

Reduction target picker: a thick rounded sage range (0–60%) with tick labels and a “science-aligned” marker, showing the resulting tonnes and a gentle verdict.

Organic SoftInput

Textarea

Soft note field: rounded sand textarea that auto-grows (field-sizing), with a live character counter that turns clay near the limit.

Organic SoftInput

Checkbox List

Round-checkbox to-do list built on native checkboxes: bouncy mint ticks, strike-through when done, meta line per item and an “x of y” counter with a progress bar.

Soft FlatInput

Day Picker

Week-strip date picker: prev/next week arrows and seven rounded day pills (weekday + number) with task-load dots (red when full); the selected day fills periwinkle.

Soft FlatInput

Input

Soft text field: rounded tinted well that turns white with a thick periwinkle ring on focus, label, optional leading icon and suffix, hint or red error message.

Soft FlatInput

Radio Cards

Native radio group rendered as big pastel cards (emoji, title, text); the chosen card lifts with a periwinkle ring and a filled radio dot.

Soft FlatInput