Debounced Search Input
Search input with built-in debounce, loading state, and clear action.
Default
Live filtered list based on debounced search value.
Debounced query: -
- Invoices
- Customers
- Subscriptions
- Usage reports
- Refunds
- Payouts
default-example.tsx
1"use client";23import { useMemo, useState } from "react";4import { DebouncedSearchInput } from "@/registry/ui";56const rows = [7 "Invoices",8 "Customers",9 "Subscriptions",10 "Usage reports",11 "Refunds",12 "Payouts",13];1415export function DebouncedSearchInputDefaultExample() {16 const [query, setQuery] = useState("");17 const [debouncedQuery, setDebouncedQuery] = useState("");1819 const filtered = useMemo(20 () =>21 rows.filter((item) =>22 item.toLowerCase().includes(debouncedQuery.toLowerCase()),23 ),24 [debouncedQuery],25 );2627 return (28 <div className="mx-auto w-full max-w-xl space-y-3">29 <DebouncedSearchInput30 value={query}31 onChange={setQuery}32 onDebouncedChange={setDebouncedQuery}33 placeholder="Search resources..."34 />35 <p className="text-xs text-muted-foreground">36 Debounced query:{" "}37 <span className="font-medium">{debouncedQuery || "-"}</span>38 </p>39 <ul className="space-y-1 text-sm">40 {filtered.map((item) => (41 <li key={item} className="rounded border bg-card px-3 py-2">42 {item}43 </li>44 ))}45 </ul>46 </div>47 );48}
Loading
Input with loading hint for pending backend queries.
Loading
loading-example.tsx
1"use client";23import { useState } from "react";4import { DebouncedSearchInput } from "@/registry/ui";56export function DebouncedSearchInputLoadingExample() {7 const [query, setQuery] = useState("");89 return (10 <div className="mx-auto w-full max-w-xl">11 <DebouncedSearchInput12 value={query}13 onChange={setQuery}14 loading15 debounceMs={500}16 placeholder="Search invoices..."17 />18 </div>19 );20}
Installation & source
Install via the shadcn CLI or copy the registry files manually.
bash
npx shadcn@latest add @tt-ui/debounced-search-input
Props
| Name | Type | Default | Description |
|---|---|---|---|
| onDebouncedChange | (value: string) => void | undefined | Called after debounce delay with current query |
| debounceMs | number | 350 | Delay before debounced callback fires |
| loading | boolean | false | Shows loading hint while searching |