Skip to content
Product block

Table Search & Filter Bar

Search, filter count and view switch, with active filters shown as removable chips so a filtered table never looks unfiltered.

180 lineslucide-reactAdded 8 Aug 2026Updated 11 Sept 2026
  • toolbar
  • search
  • filters
  • chips
  • table

What's included

  • components/data-table-toolbar.tsx
  • Needs lucide-react

Works with

  • React
  • Next.js
  • Tailwind CSS
  • TypeScript

npx hoverlab add data-table-toolbar

Or over MCP, from your editor's agent — no account needed.

License

Free to read, copy and install, for personal and non-commercial projects. Shipping it in client work or a paid product needs Pro ($79 once). The source lands in your repo and stops being ours — no attribution, nothing to upgrade.

Was this useful?

Start a page with this section — add more, order them, and leave with the page source.

Preview

Filtered byStatus:ActivePlan:Pro or Team2,847 results

Rendered live in your current theme — this is the same component whose source is below, not a screenshot of it.

Source

components/data-table-toolbar.tsx
'use client'

/**
 * <DataTableToolbar> — search, filter chips and a view switch.
 *
 * The row that sits above a table and does the work nobody budgets for.
 *
 * Active filters render as removable chips rather than staying hidden
 * inside dropdowns. A filtered table that looks identical to an unfiltered
 * one is how users conclude their data has vanished — the chips, and the
 * "Clear all" beside them, are the fix.
 *
 * The search input is `type="search"` with a label, so it gets the native
 * clear affordance and is announced as a search field.
 */

import * as React from 'react'
import { Search, SlidersHorizontal, X, LayoutGrid, List, Plus } from 'lucide-react'

export interface FilterChip {
  id: string
  label: string
  value: string
}

export interface DataTableToolbarProps {
  placeholder?: string
  initialFilters?: FilterChip[]
  resultCount?: number
  onSearch?: (term: string) => void
  onFiltersChange?: (filters: FilterChip[]) => void
  className?: string
}

const DEFAULT_FILTERS: FilterChip[] = [
  { id: 'status', label: 'Status', value: 'Active' },
  { id: 'plan', label: 'Plan', value: 'Pro or Team' },
]

export function DataTableToolbar({
  placeholder = 'Search customers',
  initialFilters = DEFAULT_FILTERS,
  resultCount = 2847,
  onSearch,
  onFiltersChange,
  className = '',
}: DataTableToolbarProps) {
  // Per-instance ids. A literal id in a reusable component is a
  // collision waiting for the second copy on the page — and a <label>
  // then resolves to whichever input rendered first.
  const uid = React.useId()
  const [term, setTerm] = React.useState('')
  const [filters, setFilters] = React.useState<FilterChip[]>(initialFilters)
  const [view, setView] = React.useState<'list' | 'grid'>('list')

  function updateFilters(next: FilterChip[]) {
    setFilters(next)
    onFiltersChange?.(next)
  }

  function handleSearch(value: string) {
    setTerm(value)
    onSearch?.(value)
  }

  return (
    <div className={`space-y-3 ${className}`}>
      <div className="flex flex-col gap-3 sm:flex-row sm:items-center">
        <div className="relative flex-1">
          <label htmlFor={`${uid}-table-search`} className="sr-only">
            {placeholder}
          </label>
          <Search
            aria-hidden
            className="pointer-events-none absolute start-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"
          />
          <input
            id={`${uid}-table-search`}
            type="search"
            value={term}
            onChange={(e) => handleSearch(e.target.value)}
            placeholder={placeholder}
            className="w-full rounded-xl border border-border/60 bg-background py-2 ps-9 pe-3 text-sm outline-none transition-shadow placeholder:text-muted-foreground focus-visible:ring-2 focus-visible:ring-primary"
          />
        </div>

        <div className="flex items-center gap-2">
          <button
            type="button"
            className="inline-flex items-center gap-2 rounded-xl border border-border/60 bg-background px-3 py-2 text-sm font-medium transition-colors hover:bg-muted"
          >
            <SlidersHorizontal aria-hidden className="h-4 w-4" />
            Filters
            {filters.length > 0 ? (
              <span className="rounded-full bg-primary/15 px-1.5 py-0.5 text-xs font-semibold text-primary">
                {filters.length}
              </span>
            ) : null}
          </button>

          {/* View switch — a radio group, since the options are exclusive. */}
          <div
            role="radiogroup"
            aria-label="View mode"
            className="flex rounded-xl border border-border/60 bg-background p-0.5"
          >
            {(
              [
                { id: 'list', icon: <List className="h-4 w-4" />, label: 'List' },
                { id: 'grid', icon: <LayoutGrid className="h-4 w-4" />, label: 'Grid' },
              ] as const
            ).map((option) => (
              <button
                key={option.id}
                type="button"
                role="radio"
                aria-checked={view === option.id}
                aria-label={`${option.label} view`}
                onClick={() => setView(option.id)}
                className={`rounded-lg p-1.5 transition-colors ${
                  view === option.id
                    ? 'bg-muted text-foreground'
                    : 'text-muted-foreground hover:text-foreground'
                }`}
              >
                {option.icon}
              </button>
            ))}
          </div>

          <button
            type="button"
            className="inline-flex items-center gap-2 rounded-xl bg-primary px-3 py-2 text-sm font-semibold text-primary-foreground transition-colors hover:bg-primary/90"
          >
            <Plus aria-hidden className="h-4 w-4" />
            Add
          </button>
        </div>
      </div>

      {/* Active filters — never leave a filtered table looking unfiltered. */}
      {filters.length > 0 ? (
        <div className="flex flex-wrap items-center gap-2">
          <span className="text-xs text-muted-foreground">Filtered by</span>

          {filters.map((filter) => (
            <span
              key={filter.id}
              className="inline-flex items-center gap-1.5 rounded-full border border-border/60 bg-card px-2.5 py-1 text-xs"
            >
              <span className="text-muted-foreground">{filter.label}:</span>
              <span className="font-medium">{filter.value}</span>
              <button
                type="button"
                onClick={() => updateFilters(filters.filter((f) => f.id !== filter.id))}
                aria-label={`Remove ${filter.label} filter`}
                className="rounded-full p-0.5 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground"
              >
                <X aria-hidden className="h-3 w-3" />
              </button>
            </span>
          ))}

          <button
            type="button"
            onClick={() => updateFilters([])}
            className="text-xs font-medium text-muted-foreground underline-offset-2 transition-colors hover:text-foreground hover:underline"
          >
            Clear all
          </button>

          <span aria-live="polite" className="ms-auto text-xs text-muted-foreground">
            {resultCount.toLocaleString('en-US')} results
          </span>
        </div>
      ) : null}
    </div>
  )
}

Before you paste

  • Styling is Tailwind utility classes on semantic tokens (bg-card, text-muted-foreground) — it inherits your theme instead of overriding it.
  • Install: npm i lucide-react
  • Every prop has a default, so it renders standalone before you wire it up.

Where it goes

Drop it at components/data-table-toolbar.tsx and import it where you need the section:

import { DataTableToolbar } from '@/components/data-table-toolbar'

Customize

2 of this block’s props are simple enough to drive from here. Change them and the block below re-renders — it is the same component whose source is above, not a mock of it. Everything else it accepts is in the table underneath.

Props

Read out of the component’s own type and signature, so this cannot drift from the source below. Every prop has a default — the component renders standalone before you pass it anything.

PropTypeDefault
placeholderstring'Search customers'
initialFiltersFilterChip[]DEFAULT_FILTERS
resultCountnumber2847
onSearch(term: string) => void—
onFiltersChange(filters: FilterChip[]) => void—
classNamestring''

Not using React?

The same block rendered once to markup, wrapped as a file your framework compiles. Tailwind classes are framework-agnostic, so the design transfers intact — the behaviour does not.

This block is interactive. The markup below is its initial state with the event handlers stripped — you will need to re-wire the behaviour in your framework.

data-table-toolbar.html
<!--
  Table Search & Filter Bar — markup from the Hoverlab catalog.

  This is the block rendered once to HTML and wrapped as a component
  file. It is not a port of the React source: the Tailwind classes carry
  the design, which is the part that took the work, and they are the same
  in every framework.

  This block is interactive in React and the handlers are NOT here.
  Buttons, toggles and menus render in their initial state and do
  nothing until you wire them up.
-->
<div class="space-y-3 ">
  <div class="flex flex-col gap-3 sm:flex-row sm:items-center">
    <div class="relative flex-1">
      <label for="_R_0_-table-search" class="sr-only">Search customers</label>
      <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-search pointer-events-none absolute start-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground" aria-hidden="true">
        <path d="m21 21-4.34-4.34"></path>
        <circle cx="11" cy="11" r="8"></circle>
      </svg>
      <input id="_R_0_-table-search" type="search" placeholder="Search customers" class="w-full rounded-xl border border-border/60 bg-background py-2 ps-9 pe-3 text-sm outline-none transition-shadow placeholder:text-muted-foreground focus-visible:ring-2 focus-visible:ring-primary" value="" />
    </div>
    <div class="flex items-center gap-2">
      <button type="button" class="inline-flex items-center gap-2 rounded-xl border border-border/60 bg-background px-3 py-2 text-sm font-medium transition-colors hover:bg-muted"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-sliders-horizontal h-4 w-4" aria-hidden="true"><line x1="21" x2="14" y1="4" y2="4"></line><line x1="10" x2="3" y1="4" y2="4"></line><line x1="21" x2="12" y1="12" y2="12"></line><line x1="8" x2="3" y1="12" y2="12"></line><line x1="21" x2="16" y1="20" y2="20"></line><line x1="12" x2="3" y1="20" y2="20"></line><line x1="14" x2="14" y1="2" y2="6"></line><line x1="8" x2="8" y1="10" y2="14"></line><line x1="16" x2="16" y1="18" y2="22"></line></svg>Filters<span class="rounded-full bg-primary/15 px-1.5 py-0.5 text-xs font-semibold text-primary">2</span></button>
      <div role="radiogroup" aria-label="View mode" class="flex rounded-xl border border-border/60 bg-background p-0.5">
        <button type="button" role="radio" aria-checked="true" aria-label="List view" class="rounded-lg p-1.5 transition-colors bg-muted text-foreground">
          <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-list h-4 w-4" aria-hidden="true">
            <path d="M3 12h.01"></path>
            <path d="M3 18h.01"></path>
            <path d="M3 6h.01"></path>
            <path d="M8 12h13"></path>
            <path d="M8 18h13"></path>
            <path d="M8 6h13"></path>
          </svg>
        </button>
        <button type="button" role="radio" aria-checked="false" aria-label="Grid view" class="rounded-lg p-1.5 transition-colors text-muted-foreground hover:text-foreground">
          <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-layout-grid h-4 w-4" aria-hidden="true">
            <rect width="7" height="7" x="3" y="3" rx="1"></rect>
            <rect width="7" height="7" x="14" y="3" rx="1"></rect>
            <rect width="7" height="7" x="14" y="14" rx="1"></rect>
            <rect width="7" height="7" x="3" y="14" rx="1"></rect>
          </svg>
        </button>
      </div>
      <button type="button" class="inline-flex items-center gap-2 rounded-xl bg-primary px-3 py-2 text-sm font-semibold text-primary-foreground transition-colors hover:bg-primary/90"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-plus h-4 w-4" aria-hidden="true"><path d="M5 12h14"></path><path d="M12 5v14"></path></svg>Add</button>
    </div>
  </div>
  <div class="flex flex-wrap items-center gap-2">
    <span class="text-xs text-muted-foreground">Filtered by</span>
    <span class="inline-flex items-center gap-1.5 rounded-full border border-border/60 bg-card px-2.5 py-1 text-xs">
      <span class="text-muted-foreground">Status:</span>
      <span class="font-medium">Active</span>
      <button type="button" aria-label="Remove Status filter" class="rounded-full p-0.5 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground">
        <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-x h-3 w-3" aria-hidden="true">
          <path d="M18 6 6 18"></path>
          <path d="m6 6 12 12"></path>
        </svg>
      </button>
    </span>
    <span class="inline-flex items-center gap-1.5 rounded-full border border-border/60 bg-card px-2.5 py-1 text-xs">
      <span class="text-muted-foreground">Plan:</span>
      <span class="font-medium">Pro or Team</span>
      <button type="button" aria-label="Remove Plan filter" class="rounded-full p-0.5 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground">
        <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-x h-3 w-3" aria-hidden="true">
          <path d="M18 6 6 18"></path>
          <path d="m6 6 12 12"></path>
        </svg>
      </button>
    </span>
    <button type="button" class="text-xs font-medium text-muted-foreground underline-offset-2 transition-colors hover:text-foreground hover:underline">Clear all</button>
    <span aria-live="polite" class="ms-auto text-xs text-muted-foreground">2,847 results</span>
  </div>
</div>
  • This is rendered HTML, not a translation of the React source. The Tailwind classes carry the design and work in any framework.
  • It is one frame: the component in its initial state, with no props applied beyond the defaults.
  • This block is interactive in React — toggles, menus or form state. None of that survives here; the markup is the closed/default state and the handlers are gone. Re-wire them in your own framework.
  • Requires Tailwind, and the design tokens the classes reference (bg-card, text-muted-foreground, and so on). The template ZIPs ship a globals.css that defines them.

What each framework gets across the whole catalog — effects convert properly; this rung is markup.

For AI

The component, its props, the design tokens it expects and the command that installs it — as one prompt. Paste it into Claude, Cursor, v0 or ChatGPT and what they build around it will match the rest of the catalog instead of inventing its own system.

See the prompt

Used in these pages

Want the whole screen instead of this one section? Open a page and copy it entire.

7 more blocks in Data Tables

All of them free to read, copy and install — no account, no locked tiles, no watermarked preview. The whole catalog is open, and so are the API and the CLI.

Browse Data Tables

Shipping one commercially

Copying the code is free. Putting it in client work or a paid product is what Pro is for — the licence, not the access.

  • A commercial licence for everything in the catalog
  • Unlimited bundle exports, in Vue, Svelte and Tailwind
  • One payment — no subscription, nothing to renew
Pro — $79 once

More Data Tables blocks

View category
Open the full page for this block

Sortable Selectable Table

Type-aware sorting with aria-sort, a header checkbox that goes properly indeterminate, and selection that survives a re-sort.

Data Tables297 lines1 dep
Open the full page for this block

Expandable Detail Rows

Rows that open into a full-width detail panel via colSpan, with aria-expanded and aria-controls wired to the detail row.

Data Tables205 lines1 dep
Open the full page for this block

Column Show, Hide & Reorder

Reordering that works from the keyboard rather than by drag alone, pinned columns that cannot be hidden or moved, and a guard so the last visible column cannot be unchecked into a blank table.

Data Tables219 lines1 dep
Open the full page for this block

Bulk Action Bar

The selection bar that asks the question most tables skip: this page, or all 1,284 rows the filter matches. Typed confirmation above a threshold, an undo with the window counting down, and a select-all that names its own scope.

Data Tables405 lines1 dep
Open the full page for this block

Inline Editable Table

Edit cells in the grid with staged changes, per-cell validation, the original value kept beside the attempt, and a save that counts what is still pending.

Data Tables301 lines1 dep
Open the full page for this block

Grouped Table with Subtotals

Collapsible group headers that carry their own subtotals while collapsed, with a grand total that sums every row rather than only the visible ones.

Data Tables238 lines1 dep