diff --git a/.changeset/chilly-buses-sort.md b/.changeset/chilly-buses-sort.md new file mode 100644 index 00000000..5bb1ba87 --- /dev/null +++ b/.changeset/chilly-buses-sort.md @@ -0,0 +1,5 @@ +--- +"@clack/prompts": minor +--- + +add wraparound behaviour to autocomplete components diff --git a/packages/core/src/prompts/autocomplete.ts b/packages/core/src/prompts/autocomplete.ts index f72d205c..43cd6227 100644 --- a/packages/core/src/prompts/autocomplete.ts +++ b/packages/core/src/prompts/autocomplete.ts @@ -1,10 +1,12 @@ import type { Key } from 'node:readline'; import color from 'picocolors'; import Prompt, { type PromptOptions } from './prompt.js'; +import { findCursor } from '../utils/cursor.js'; interface OptionLike { value: unknown; label?: string; + disabled?: boolean; } type FilterFunction = (search: string, opt: T) => boolean; @@ -143,10 +145,7 @@ export default class AutocompletePrompt extends Prompt< // Start navigation mode with up/down arrows if (isUpKey || isDownKey) { - this.#cursor = Math.max( - 0, - Math.min(this.#cursor + (isUpKey ? -1 : 1), this.filteredOptions.length - 1) - ); + this.#cursor = findCursor(this.#cursor, isUpKey ? -1 : 1, this.filteredOptions); this.focusedValue = this.filteredOptions[this.#cursor]?.value; if (!this.multiple) { this.selectedValues = [this.focusedValue];