Skip to content

Commit 85f6aff

Browse files
authored
fix(prompts): render falsy options in limitOptions (#628)
1 parent 1835f41 commit 85f6aff

3 files changed

Lines changed: 16 additions & 1 deletion

File tree

‎.changeset/quiet-options-render.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@clack/prompts': patch
3+
---
4+
5+
Render falsy primitive options through the `limitOptions` style callback instead of leaving blank rows.

‎packages/prompts/src/limit-options.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ export const limitOptions = <TOption>({
149149

150150
for (let i = slidingWindowLocationWithEllipsis; i < slidingWindowLocationEndWithEllipsis; i++) {
151151
const option = options[i];
152-
const styledOption = option ? style(option, i === cursor) : '';
152+
const styledOption = option !== undefined ? style(option, i === cursor) : '';
153153
const wrappedLines = wrapAnsi(styledOption, maxWidth, {
154154
hard: true,
155155
trim: false,

‎packages/prompts/test/limit-options.test.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,16 @@ describe('limitOptions', () => {
9393
expect(result).toEqual([]);
9494
});
9595

96+
test('styles falsy primitive options and identifies the active option', () => {
97+
const result = limitOptions({
98+
output,
99+
options: [0, false, '', 1],
100+
cursor: 1,
101+
style: (option, active) => `${active ? '> ' : ''}[${String(option)}]`,
102+
});
103+
expect(result).toEqual(['[0]', '> [false]', '[]', '[1]']);
104+
});
105+
96106
test('if items exceed output height, clamp to fit', async () => {
97107
options.options = [
98108
{ value: 'Item 1' },

0 commit comments

Comments
 (0)