Skip to content

Conversation

@danielroe
Copy link
Contributor

@danielroe danielroe commented Jan 19, 2026

Summary

a custom filter opt is support in multiselect - would be nice to do the same for the autocomplete version 🙏

Motivation

related PR: nuxt/cli#1180

The @clack/core package already supports custom filter functions via the AutocompletePrompt class, but this wasn't exposed in the higher-level @clack/prompts API. This is useful for:

  • Implementing fuzzy search (e.g., using fzf library)
  • Custom matching logic (prefix-only, regex-based, etc.)
  • Searching additional fields beyond label/hint/value

Changes

  • Added filter?: (search: string, option: Option<Value>) => boolean to AutocompleteSharedOptions
  • Updated autocomplete() and autocompleteMultiselect() to pass through the custom filter, falling back to the default filter when not provided
  • Added tests for custom filter functionality

Example Usage

import { autocompleteMultiselect } from '@clack/prompts'
import { Fzf } from 'fzf'

const options = [
  { value: 'apple', label: 'Apple' },
  { value: 'banana', label: 'Banana' },
]

const fzf = new Fzf(options, { selector: (opt) => opt.label })

const result = await autocompleteMultiselect({
  message: 'Select fruits',
  options,
  filter: (search, option) => {
    if (!search) return true
    return fzf.find(search).some((r) => r.item.value === option.value)
  },
})

@changeset-bot
Copy link

changeset-bot bot commented Jan 19, 2026

🦋 Changeset detected

Latest commit: 73af0a8

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@clack/prompts Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Collaborator

@43081j 43081j left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense to me 👍

can you add a changeset? (npx changeset)

@danielroe
Copy link
Contributor Author

done! ❤️

@pkg-pr-new
Copy link

pkg-pr-new bot commented Jan 19, 2026

commit: 73af0a8

@43081j 43081j merged commit 415410b into bombshell-dev:main Jan 19, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants