fix(nav): Use capture-phase listener so Cmd+K works when inputs have focus#111443
fix(nav): Use capture-phase listener so Cmd+K works when inputs have focus#111443
Conversation
…focus Components like the search query builder call stopPropagation() on keydown events, preventing them from reaching the document-level listener in useHotkeys. This adds a useCapture option to useHotkeys that registers the listener on the capture phase, firing before any child component can stop propagation.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
| expect(callback).toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it('registers on capture phase with useCapture', () => { |
There was a problem hiding this comment.
Test mock overwrites bubble handler with capture handler
High Severity
The test mock for document.addEventListener stores callbacks by event name (events[event] = callback), so only one callback survives per event. Since useHotkeys now registers two 'keydown' listeners (bubble then capture), the capture handler overwrites the bubble handler in events. All existing tests that invoke events.keydown!(evt) with non-useCapture hotkeys now silently run the capture handler, which skips those hotkeys due to the !!hotkey.useCapture !== capture guard. This breaks every pre-existing test case that expects a bubble-phase callback to fire.
Additional Locations (1)
| @@ -42,6 +42,8 @@ function UserAndOrganizationNavigation() { | |||
| : [ | |||
| { | |||
| match: ['command+shift+p', 'command+k', 'ctrl+shift+p', 'ctrl+k'], | |||
| includeInputs: true, | |||
| useCapture: true, | |||
There was a problem hiding this comment.
Can we start with just includeInputs for now?
|
This issue has gone three weeks without activity. In another week, I will close it. But! If you comment or otherwise update it, I will reset the clock, and if you remove the label "A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀 |


Summary
useCaptureoption touseHotkeysthat registers the keydown listener on the capture phasestopPropagation()on keydown events, which prevents shortcuts from reaching the document-level bubble listener. Capture-phase listeners fire before any component can stop propagation.useCapture: trueandincludeInputs: trueto the Cmd+K command palette shortcutTest plan
useCapturecontinue to work as before