Skip to content
Open
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/quiet-options-render.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@clack/prompts': patch
---

Render falsy primitive options through the `limitOptions` style callback instead of leaving blank rows.
2 changes: 1 addition & 1 deletion packages/prompts/src/limit-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ export const limitOptions = <TOption>({

for (let i = slidingWindowLocationWithEllipsis; i < slidingWindowLocationEndWithEllipsis; i++) {
const option = options[i];
const styledOption = option ? style(option, i === cursor) : '';
const styledOption = option !== undefined ? style(option, i === cursor) : '';
const wrappedLines = wrapAnsi(styledOption, maxWidth, {
hard: true,
trim: false,
Expand Down
10 changes: 10 additions & 0 deletions packages/prompts/test/limit-options.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,16 @@ describe('limitOptions', () => {
expect(result).toEqual([]);
});

test('styles falsy primitive options and identifies the active option', () => {
const result = limitOptions({
output,
options: [0, false, '', 1],
cursor: 1,
style: (option, active) => `${active ? '> ' : ''}[${String(option)}]`,
});
expect(result).toEqual(['[0]', '> [false]', '[]', '[1]']);
});

test('if items exceed output height, clamp to fit', async () => {
options.options = [
{ value: 'Item 1' },
Expand Down
Loading