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.jsonGuidelines
- Pass
tags+onTagsChangeto enable search tags;onSearch(query, tags)fires as the user types. - Use tags for scoped search (status:active, owner:me).
Props
| Prop | Type | Required |
|---|---|---|
tags | Array<string | { label: string }> | No |
onTagsChange | (tags: any[]) => void | No |
onSearch | (query: string, tags: any[]) => void | No |
onClear | () => void | No |
tagOnEnter | boolean | No |
size | 'sm' | 'md' | No |
Also accepts everything in Omit<React.InputHTMLAttributes<HTMLInputElement>, 'size' | 'prefix'>.