Toolforge Docs
DocsIO PrimitivessearchInput

searchInput

Provides a searchable input with dynamic option loading via a search handler function.

Usage

Search input

const product = await io.searchInput({
  label: 'Search Product',
  handleSearch: async (query) => {
    const products = await fetchProducts(query)
    return products.map((p) => ({
      label: p.name,
      value: p.id,
      description: p.price,
    }))
  },
})

Props

PropDescriptionTypeRequiredDefault
labelThe label for the search inputstringYes
descriptionThe description for the search inputstringNoundefined
modeThe mode of the search input'single' | 'multiple'No'single'
optionalWhether the search input is optionalbooleanNofalse
minThe minimum number of options that must be selected (multiple mode only)numberNoundefined
maxThe maximum number of options that can be selected (multiple mode only)numberNoundefined
handleSearchThe function to handle search queries. Should return a list of options based on the query(query: string) => Promise<SelectOption[]> | SelectOption[]Yes

Returns

Returns a Promise<string> (single mode) or Promise<string[]> (multiple mode). Return type includes | undefined if optional: true.

Examples

Multi Search Input

const tags = await io.searchInput({
  label: 'Add Tags',
  mode: 'multiple',
  min: 1,
  max: 5,
  handleSearch: async (query) => {
    const tags = await searchTags(query)
    return tags.map((tag) => ({ label: tag.name, value: tag.id }))
  },
})

// Returns: string[] (array of selected values)

On this page