@@ -51,6 +51,13 @@ export interface AutocompleteOptions<T extends OptionLike>
5151 options : T [ ] | ( ( this : AutocompletePrompt < T > ) => T [ ] ) ;
5252 filter ?: FilterFunction < T > ;
5353 multiple ?: boolean ;
54+ /**
55+ * When set (non-empty), pressing Tab with no input fills the field with this value
56+ * and runs the normal filter/selection logic so the user can confirm with Enter.
57+ * Tab only fills the input when the placeholder matches at least one option under
58+ * the prompt's filter (so the value remains selectable).
59+ */
60+ placeholder ?: string ;
5461}
5562
5663export default class AutocompletePrompt < T extends OptionLike > extends Prompt <
@@ -66,6 +73,7 @@ export default class AutocompletePrompt<T extends OptionLike> extends Prompt<
6673 #lastUserInput = '' ;
6774 #filterFn: FilterFunction < T > ;
6875 #options: T [ ] | ( ( ) => T [ ] ) ;
76+ #placeholder: string | undefined ;
6977
7078 get cursor ( ) : number {
7179 return this . #cursor;
@@ -94,6 +102,7 @@ export default class AutocompletePrompt<T extends OptionLike> extends Prompt<
94102 super ( opts ) ;
95103
96104 this . #options = opts . options ;
105+ this . #placeholder = opts . placeholder ;
97106 const options = this . options ;
98107 this . filteredOptions = [ ...options ] ;
99108 this . multiple = opts . multiple === true ;
@@ -143,6 +152,24 @@ export default class AutocompletePrompt<T extends OptionLike> extends Prompt<
143152 const isDownKey = key . name === 'down' ;
144153 const isReturnKey = key . name === 'return' ;
145154
155+ // Tab with empty input and placeholder: fill input with placeholder to trigger autocomplete
156+ // Only when the placeholder matches at least one (non-disabled) option so the value remains selectable
157+ const isEmptyOrOnlyTab = this . userInput === '' || this . userInput === '\t' ;
158+ const placeholder = this . #placeholder;
159+ const options = this . options ;
160+ const placeholderMatchesOption =
161+ placeholder !== undefined &&
162+ placeholder !== '' &&
163+ options . some ( ( opt ) => ! opt . disabled && this . #filterFn( placeholder , opt ) ) ;
164+ if ( key . name === 'tab' && isEmptyOrOnlyTab && placeholderMatchesOption ) {
165+ if ( this . userInput === '\t' ) {
166+ this . _clearUserInput ( ) ;
167+ }
168+ this . _setUserInput ( placeholder , true ) ;
169+ this . isNavigating = false ;
170+ return ;
171+ }
172+
146173 // Start navigation mode with up/down arrows
147174 if ( isUpKey || isDownKey ) {
148175 this . #cursor = findCursor ( this . #cursor, isUpKey ? - 1 : 1 , this . filteredOptions ) ;
0 commit comments