Skip to content

Commit e847ad4

Browse files
authored
feat(cli): add keyboard shortcuts help to multiselect prompts (#227)
- Add note() before first multiselect to show keyboard shortcuts - Help text: Use ↑/↓ to navigate • Space to select/deselect • Enter to confirm - Show help only once to avoid cluttering the interface - Add unit test to verify note() is called with correct message Improves UX by helping users understand multiselect navigation
1 parent 5858712 commit e847ad4

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

packages/cta-cli/src/ui-prompts.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
confirm,
44
isCancel,
55
multiselect,
6+
note,
67
select,
78
text,
89
} from '@clack/prompts'
@@ -103,6 +104,9 @@ export async function selectPackageManager(): Promise<PackageManager> {
103104
return packageManager
104105
}
105106

107+
// Track if we've shown the multiselect help text
108+
let hasShownMultiselectHelp = false
109+
106110
export async function selectAddOns(
107111
framework: Framework,
108112
mode: string,
@@ -116,6 +120,12 @@ export async function selectAddOns(
116120
return []
117121
}
118122

123+
// Show help text only once
124+
if (!hasShownMultiselectHelp) {
125+
note('Use ↑/↓ to navigate • Space to select/deselect • Enter to confirm', 'Keyboard Shortcuts')
126+
hasShownMultiselectHelp = true
127+
}
128+
119129
const value = await multiselect({
120130
message,
121131
options: addOns

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ describe('selectPackageManager', () => {
9393
})
9494

9595
describe('selectAddOns', () => {
96-
it('should select some add-ons', async () => {
96+
it('should show keyboard shortcuts help and select add-ons', async () => {
97+
const noteSpy = vi.spyOn(clack, 'note').mockImplementation(() => {})
9798
vi.spyOn(clack, 'multiselect').mockImplementation(async () => ['add-on-1'])
9899
vi.spyOn(clack, 'isCancel').mockImplementation(() => false)
99100

@@ -114,7 +115,12 @@ describe('selectAddOns', () => {
114115
'add-on',
115116
'Select add-ons',
116117
)
118+
117119
expect(packageManager).toEqual(['add-on-1'])
120+
expect(noteSpy).toHaveBeenCalledWith(
121+
'Use ↑/↓ to navigate • Space to select/deselect • Enter to confirm',
122+
'Keyboard Shortcuts',
123+
)
118124
})
119125

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

0 commit comments

Comments
 (0)