inquirer-table-multiple

March 15, 2026 · View on GitHub

npm version codecov Tests

Interactive table component for command line interfaces.

Choose between choices? (Press <space> to select, <Up and Down> to move rows,
<Left and Right> to move columns)

┌──────────┬────────┬────────┐
 1-2 of 2 Yes? No?    |
├──────────┼────────┼────────┤
 Choice 1 [  ]   |
├──────────┼────────┼────────┤
 Choice 2   |
└──────────┴────────┴────────┘

Installation

npm install @bartheleway/inquirer-table-multiple

yarn add @bartheleway/inquirer-table-multiple

Usage

import tableMultiple from '@bartheleway/inquirer-table-multiple'

const answer = await tableMultiple({
	message: 'Choose between choices?',
	columns: [
		{
			title: 'Yes?'
			value: 1,
		},
		{
			title: 'No?'
			value: 0,
		},
	],
	rows: [
		{
			value: 1,
			title: 'Choice 1',
		},
		{
			value: 2,
			title: 'Choice 2',
		}
	],
})

Options

PropertyTypeRequiredDescriptionDefault
allowUnsetbooleannoIf multiple is set to false and this one to true, you can unselect the selected choice.false
columns(TableQuestionColumn<Value> | TableColumn)[]yesThe list of columns to display.
ignoreEmptyAnswersbooleannoIndicate if validate, sumUp and output contains rows with no answers or not.true
loopbooleannoIndicate if you can loop over table rows.true
messagestringyesThe question to ask.
multiplebooleannoIndicate if rows allows multiple choices or not.false
pageSizenumbernoThe number of lines to display.7
requiredbooleannoIndicate if at least one choice is necessary.false
rows(TableRow | Separator)[]yesThe list of rows. Each row offer a choice which can be multiple (radio vs checkbox vs checkbox-multi) based on the mode option.
sumUpTableAnswers<Value> => stringnoThis allow to display a resume of selected answers to user after validation.
validateTableAnswers<Value> => boolean | string | Promise<string | boolean>noOn submit, validate the answered content. When returning a string, it'll be used as the error message displayed to the user. Note: returning a rejected promise, we'll assume a code error happened and crash.

Columns

Column definition will be used to make the header row of the table.

You can have addition information column by using TableQuestionColumn<Value>with an object attribute name of the value used in rows. In this case, value of TableRow must be an object.

type TableColumn = {
	title: string,
	value: string | number | undefined,
}

type TableQuestionColumn<Value> = {
	title: string,
	rowAttributeTarget: keyof Value,
}

Rows

Row definition will be used to generate each rows of the table. A disabled row will display as usual but without any selectable choice.

title will be used as first column label to differenciate each row.

A separator will span over all columns and display its separator param.

type TableRow<Value> = {
	title: string,
	value: Value,
	disabled?: boolean,
	default?: (string | number)[]
}

Returned value

This inquirer prompt will return an array. Each responded row will contains the row value (choice) along with selected answers. By default only rows with answers will be returned, you can change this with ignoreEmptyAnswers: false

type TableAnswers<Value> = TableAnswer<Value>[]

type TableAnswer<Value> = {
	choice: TableRow<Value>[],
	answers: (string | number)[],
}

Advance usage & exemples

You can have a look to tests files to look for advanced usage.

Testing

Some OS doesn't trim test result lines so you can set an environment variable FIX_OS_EXTRA_SPACE=1 to fix that and enable having consistent result with local & remote runner.

The simpliest way is to replace test entry value in package.json with FIX_OS_EXTRA_SPACE=1 && vitest.

License

Copyright (c) 2024 Bartheleway Licensed under the MIT license.