@@ -236,6 +236,52 @@ describe('CommandPalette', () => {
236236 expect ( document . activeElement ) . toBe ( input )
237237 } )
238238
239+ it ( 'moves focus through commands with Ctrl+N and Ctrl+P' , async ( ) => {
240+ await mountPalette ( )
241+
242+ const input = document . getElementById ( 'command-palette-modal-input' )
243+ const commands = Array . from (
244+ document . querySelectorAll < HTMLElement > ( '[data-command-item="true"]' ) ,
245+ )
246+
247+ expect ( document . activeElement ) . toBe ( input )
248+
249+ document . dispatchEvent ( new KeyboardEvent ( 'keydown' , { bubbles : true , ctrlKey : true , key : 'n' } ) )
250+ await nextTick ( )
251+ expect ( document . activeElement ) . toBe ( commands [ 0 ] )
252+
253+ document . dispatchEvent ( new KeyboardEvent ( 'keydown' , { bubbles : true , ctrlKey : true , key : 'n' } ) )
254+ await nextTick ( )
255+ expect ( document . activeElement ) . toBe ( commands [ 1 ] )
256+
257+ document . dispatchEvent ( new KeyboardEvent ( 'keydown' , { bubbles : true , ctrlKey : true , key : 'p' } ) )
258+ await nextTick ( )
259+ expect ( document . activeElement ) . toBe ( commands [ 0 ] )
260+
261+ document . dispatchEvent ( new KeyboardEvent ( 'keydown' , { bubbles : true , ctrlKey : true , key : 'p' } ) )
262+ await nextTick ( )
263+ expect ( document . activeElement ) . toBe ( input )
264+ } )
265+
266+ it ( 'does not navigate with Ctrl+N/P when additional modifiers are held' , async ( ) => {
267+ await mountPalette ( )
268+
269+ const input = document . getElementById ( 'command-palette-modal-input' )
270+ expect ( document . activeElement ) . toBe ( input )
271+
272+ document . dispatchEvent (
273+ new KeyboardEvent ( 'keydown' , { bubbles : true , ctrlKey : true , altKey : true , key : 'n' } ) ,
274+ )
275+ await nextTick ( )
276+ expect ( document . activeElement ) . toBe ( input )
277+
278+ document . dispatchEvent (
279+ new KeyboardEvent ( 'keydown' , { bubbles : true , ctrlKey : true , shiftKey : true , key : 'p' } ) ,
280+ )
281+ await nextTick ( )
282+ expect ( document . activeElement ) . toBe ( input )
283+ } )
284+
239285 it ( 'does not change the active command when another item is hovered' , async ( ) => {
240286 await mountPalette ( )
241287
0 commit comments