Skip to content

Token Definitions

Token definitions describe the structured keys your search input recognizes. Each definition configures a key name, display label, available options, and validation rules.

const tokens = [
{
key: 'status',
label: 'Status',
options: [
{ value: 'active', label: 'Active' },
{ value: 'inactive', label: 'Inactive' },
],
},
]
PropertyTypeDescription
keystringInternal key name (e.g. 'status')
labelstring?Display label in the suggestion dropdown. Defaults to key.
optionsTokenOption[] | (query, signal) => ...Static or async options
iconReactNode?Icon shown in the key suggestion dropdown
exclusiveboolean?Only one instance of this key allowed
strictboolean?Value must match a provided option
negatableboolean?Enable not: prefix for negation
renderDropdown(props) => ReactNodeCustom dropdown renderer

Set exclusive: true to allow only one instance of a key in the query. If a user tries to add a second status: token, it won’t appear in the suggestion dropdown:

{ key: 'status', exclusive: true, options: [...] }

Set strict: true to require values match one of the provided options. Invalid values will not be highlighted as tokens:

{ key: 'priority', strict: true, options: [...] }

Options can be fetched dynamically. The function receives the current query text and an AbortSignal for cancellation:

{
key: 'customer',
label: 'Customer',
options: async (query, signal) => {
const res = await fetch(`/api/customers?q=${query}`, { signal })
return res.json()
},
}

Enable negation with negatable: true. A “Not” option appears in the value dropdown, allowing users to negate values (e.g. status:not:active):

{ key: 'status', negatable: true, options: [...] }

Customize the negation label for i18n with the negationLabel prop on the component:

<TokenizedSearch negationLabel="nicht" ... />

Replace the default dropdown for a token with a fully custom renderer:

{
key: 'date',
renderDropdown: ({ value, onChange, close }) => (
<DatePicker
value={value}
onChange={(v) => onChange(v, true)} // true = close dropdown
/>
),
}

The renderDropdown callback receives:

PropTypeDescription
valuestringCurrent token value
onChange(value, closeDropdown?) => voidUpdate the value
close() => voidClose the dropdown

Each option in the options array has:

PropertyTypeDescription
valuestringInternal value (emitted in segments)
labelstring?Display text. Defaults to value.
idstring?Optional identifier passed through to parsed segments