@@ -41,45 +41,83 @@ function getSelectedOptions<T>(values: T[], options: Option<T>[]): Option<T>[] {
4141 return results ;
4242}
4343
44+ /**
45+ * Options for the {@link autocomplete} prompt.
46+ */
4447interface AutocompleteSharedOptions < Value > extends CommonOptions {
4548 /**
46- * The message to display to the user.
49+ * The prompt message or question shown to the user above the input .
4750 */
4851 message : string ;
52+
4953 /**
50- * Available options for the autocomplete prompt.
54+ * The options to present, or a function that returns the options to present
55+ * allowing for custom search/filtering.
56+ *
57+ * @see https://bomb.sh/docs/clack/packages/prompts/#dynamic-options-getter
5158 */
5259 options : Option < Value > [ ] | ( ( this : AutocompletePrompt < Option < Value > > ) => Option < Value > [ ] ) ;
60+
5361 /**
54- * Maximum number of items to display at once.
62+ * The maximum number of items/options to display in the autocomplete list at once.
5563 */
5664 maxItems ?: number ;
65+
5766 /**
58- * Placeholder text to display when no input is provided.
67+ * Placeholder text displayed when the search field is empty. When set, pressing
68+ * tab copies the placeholder into the input.
5969 */
6070 placeholder ?: string ;
71+
6172 /**
62- * Validates the value
73+ * A function that validates user input. Return a `string` or `Error` to show as a
74+ * validation error, or `undefined` to accept the result.
6375 */
6476 validate ?: ( value : Value | Value [ ] | undefined ) => string | Error | undefined ;
77+
6578 /**
66- * Custom filter function to match options against search input.
67- * If not provided, a default filter that matches label, hint, and value is used.
79+ * Custom filter function to match options against the search input.
6880 */
6981 filter ?: ( search : string , option : Option < Value > ) => boolean ;
7082}
7183
7284export interface AutocompleteOptions < Value > extends AutocompleteSharedOptions < Value > {
7385 /**
74- * The initial selected value .
86+ * The initially selected option from the list .
7587 */
7688 initialValue ?: Value ;
89+
7790 /**
78- * The initial user input
91+ * The starting value shown in the users input box.
7992 */
8093 initialUserInput ?: string ;
8194}
8295
96+ /**
97+ * The `autocomplete` prompt combines a text input with a searchable list of options.
98+ * It's perfect for when you have a large list of options and want to help users
99+ * find what they're looking for quickly.
100+ *
101+ * @see https://bomb.sh/docs/clack/packages/prompts/#autocomplete
102+ *
103+ * @example
104+ * ```ts
105+ * import { autocomplete } from '@clack/prompts';
106+ *
107+ * const framework = await autocomplete({
108+ * message: 'Search for a framework',
109+ * options: [
110+ * { value: 'next', label: 'Next.js', hint: 'React framework' },
111+ * { value: 'astro', label: 'Astro', hint: 'Content-focused' },
112+ * { value: 'svelte', label: 'SvelteKit', hint: 'Compile-time framework' },
113+ * { value: 'remix', label: 'Remix', hint: 'Full stack framework' },
114+ * { value: 'nuxt', label: 'Nuxt', hint: 'Vue framework' },
115+ * ],
116+ * placeholder: 'Type to search...',
117+ * maxItems: 5,
118+ * });
119+ * ```
120+ */
83121export const autocomplete = < Value > ( opts : AutocompleteOptions < Value > ) => {
84122 const prompt = new AutocompletePrompt ( {
85123 options : opts . options ,
@@ -223,20 +261,45 @@ export const autocomplete = <Value>(opts: AutocompleteOptions<Value>) => {
223261 return prompt . prompt ( ) as Promise < Value | symbol > ;
224262} ;
225263
226- // Type definition for the autocompleteMultiselect component
264+ /**
265+ * Options for the {@link autocompleteMultiselect} prompt
266+ */
227267export interface AutocompleteMultiSelectOptions < Value > extends AutocompleteSharedOptions < Value > {
228268 /**
229- * The initial selected values
269+ * The initially selected option(s) from the list.
230270 */
231271 initialValues ?: Value [ ] ;
272+
232273 /**
233- * If true, at least one option must be selected
274+ * When `true`, at least one option must be selected.
275+ * @default false
234276 */
235277 required ?: boolean ;
236278}
237279
238280/**
239- * Integrated autocomplete multiselect - combines type-ahead filtering with multiselect in one UI
281+ * The `autocompleteMultiselect` prompt combines the search functionality of autocomplete
282+ * with the ability to select multiple options.
283+ *
284+ * @see https://bomb.sh/docs/clack/packages/prompts/#autocomplete-multiselect
285+ *
286+ * @example
287+ * ```ts
288+ * import { autocompleteMultiselect } from '@clack/prompts';
289+ *
290+ * const frameworks = await autocompleteMultiselect({
291+ * message: 'Select frameworks',
292+ * options: [
293+ * { value: 'next', label: 'Next.js', hint: 'React framework' },
294+ * { value: 'astro', label: 'Astro', hint: 'Content-focused' },
295+ * { value: 'svelte', label: 'SvelteKit', hint: 'Compile-time framework' },
296+ * { value: 'remix', label: 'Remix', hint: 'Full stack framework' },
297+ * { value: 'nuxt', label: 'Nuxt', hint: 'Vue framework' },
298+ * ],
299+ * placeholder: 'Type to search...',
300+ * maxItems: 5,
301+ * });
302+ * ```
240303 */
241304export const autocompleteMultiselect = < Value > ( opts : AutocompleteMultiSelectOptions < Value > ) => {
242305 const formatOption = (
0 commit comments