Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/chilly-buses-sort.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@clack/prompts": minor
---

add wraparound behaviour to autocomplete components
7 changes: 3 additions & 4 deletions packages/core/src/prompts/autocomplete.ts
Original file line number Diff line number Diff line change
@@ -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<T extends OptionLike> = (search: string, opt: T) => boolean;
Expand Down Expand Up @@ -143,10 +145,7 @@ export default class AutocompletePrompt<T extends OptionLike> 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];
Expand Down
Loading