Skip to content

Commit e384620

Browse files
committed
fix(cli): avoid paginated add-on multiselect glitch
Set multiselect maxItems to the full selectable add-on count so Clack pagination markers are not used for this prompt, preventing duplicated option rendering near the bottom of the list. Fixes #352
1 parent 5079a7c commit e384620

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

.changeset/fair-trees-grab.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@tanstack/cli": patch
3+
---
4+
5+
Prevent add-on multiselect options from rendering with pagination markers by showing the full list, which avoids a Clack navigation glitch that could duplicate the second-to-last entry while moving between the bottom options.

packages/cli/src/ui-prompts.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,22 @@ export async function selectAddOns(
8686
}
8787

8888
if (allowMultiple) {
89+
const selectableAddOns = addOns.filter(
90+
(addOn) => !forcedAddOns.includes(addOn.id),
91+
)
92+
93+
if (selectableAddOns.length === 0) {
94+
return []
95+
}
96+
8997
const value = await multiselect({
9098
message,
91-
options: addOns
92-
.filter((addOn) => !forcedAddOns.includes(addOn.id))
93-
.map((addOn) => ({
99+
options: selectableAddOns.map((addOn) => ({
94100
value: addOn.id,
95101
label: addOn.name,
96102
hint: addOn.description,
97103
})),
104+
maxItems: selectableAddOns.length,
98105
required: false,
99106
})
100107

packages/cli/tests/ui-prompts.test.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ describe('selectPackageManager', () => {
5757
describe('selectAddOns', () => {
5858
it('should show keyboard shortcuts help and select add-ons', async () => {
5959
const noteSpy = vi.spyOn(clack, 'note').mockImplementation(() => {})
60-
vi.spyOn(clack, 'multiselect').mockImplementation(async () => ['add-on-1'])
60+
const multiselectSpy = vi
61+
.spyOn(clack, 'multiselect')
62+
.mockImplementation(async () => ['add-on-1'])
6163
vi.spyOn(clack, 'isCancel').mockImplementation(() => false)
6264

6365
const packageManager = await selectAddOns(
@@ -83,6 +85,9 @@ describe('selectAddOns', () => {
8385
'Use ↑/↓ to navigate • Space to select/deselect • Enter to confirm',
8486
'Keyboard Shortcuts',
8587
)
88+
expect(multiselectSpy).toHaveBeenCalledWith(
89+
expect.objectContaining({ maxItems: 1 }),
90+
)
8691
})
8792

8893
it('should exit on cancel', async () => {

0 commit comments

Comments
 (0)