DocsComponentsTemplatesThemesGitHub

SearchField

Pill search input that can hold search tags (tokens); Enter turns the text into a tag, Backspace removes the last one.

Code

import * as React from 'react';
import { SearchField } from '@fruit-labs/design';

export default function Demo() {
  const [t, set] = React.useState(['status: active', 'owner: me']);
  return (
    <div
      style={{
        maxWidth: 460,
      }}
    >
      <SearchField placeholder="Search projects" tags={t} onTagsChange={set} />
    </div>
  );
}

Install

From npm:

npm install @fruit-labs/design

import { SearchField } from '@fruit-labs/design';

Or copy the TypeScript source into your project:

npx shadcn@latest add https://design.fruitlabs.online/r/search-field.json

Guidelines

  • Pass tags + onTagsChange to enable search tags; onSearch(query, tags) fires as the user types.
  • Use tags for scoped search (status:active, owner:me).

Props

PropTypeRequired
tagsArray<string | { label: string }>No
onTagsChange(tags: any[]) => voidNo
onSearch(query: string, tags: any[]) => voidNo
onClear() => voidNo
tagOnEnterbooleanNo
size'sm' | 'md'No

Also accepts everything in Omit<React.InputHTMLAttributes<HTMLInputElement>, 'size' | 'prefix'>.

Edit this example on GitHub