autocompleteMultiselect errors on invalid option
Author: asportnoyCreated Jun 10, 2024Updated Feb 18, 2025
Describe the bug
When using an autocompleteMultiselect prompt, pressing space to select when there's no results for a filter causes a crash.
To Reproduce
Run this code:
import prompts from 'prompts';
await prompts({
type: 'autocompleteMultiselect',
name: 'test',
message: 'Enter some gibberish below, then press space',
choices: [
{
title: 'Foo',
value: 'Foo',
},
],
});- Type some random text so no results match the filter
- Press space to "select" this option
- Error:
node:internal/readline/emitKeypressEvents:74
throw err;
^
TypeError: Cannot read properties of undefined (reading 'selected')
at AutocompleteMultiselectPrompt.handleSpaceToggle (/Users/albert/Documents/repo/node_modules/prompts/lib/elements/autocompleteMultiselect.js:101:11)
at AutocompleteMultiselectPrompt._ (/Users/albert/Documents/repo/node_modules/prompts/lib/elements/autocompleteMultiselect.js:119:12)
at ReadStream.keypress (/Users/albert/Documents/repo/node_modules/prompts/lib/elements/prompt.js:30:24)
at ReadStream.emit (node:events:518:28)
at emitKeys (node:internal/readline/utils:371:14)
at emitKeys.next (<anonymous>)
at ReadStream.onData (node:internal/readline/emitKeypressEvents:64:36)
at ReadStream.emit (node:events:530:35)
at addChunk (node:internal/streams/readable:559:12)
at readableAddChunkPushByteMode (node:internal/streams/readable:510:3)
Node.js v20.12.2Expected behavior
Likely should do nothing, but definitely shouldn't be erroring
System
- OS: macOS Sonoma 14.5
- Terminal: iTerm 3.5.0
- Node version: v20.12.2
Additional context
N/A
Source: terkelg/prompts