1- import { useCallback , useRef , useState } from "react" ;
1+ import { useCallback , useEffect , useRef , useState } from "react" ;
22import { useOutsideClickDetector } from "@plane/hooks" ;
33
44type UseExpandableSearchOptions = {
@@ -8,6 +8,7 @@ type UseExpandableSearchOptions = {
88/**
99 * Custom hook for expandable search input behavior
1010 * Handles focus management to prevent unwanted opening on programmatic focus restoration
11+ * Opens on click, typing, or keyboard shortcut (via PowerK Cmd+F)
1112 */
1213export const useExpandableSearch = ( options ?: UseExpandableSearchOptions ) => {
1314 const { onClose } = options || { } ;
@@ -19,6 +20,7 @@ export const useExpandableSearch = (options?: UseExpandableSearchOptions) => {
1920 const containerRef = useRef < HTMLDivElement > ( null ) ;
2021 const inputRef = useRef < HTMLInputElement > ( null ) ;
2122 const wasClickedRef = useRef < boolean > ( false ) ;
23+ const wasKeyboardTriggeredRef = useRef < boolean > ( false ) ;
2224
2325 // Handle close
2426 const handleClose = useCallback ( ( ) => {
@@ -37,16 +39,32 @@ export const useExpandableSearch = (options?: UseExpandableSearchOptions) => {
3739 // Outside click detection
3840 useOutsideClickDetector ( containerRef , handleOutsideClick ) ;
3941
42+ // Track keyboard shortcuts that trigger focus (Cmd+F / Ctrl+F)
43+ useEffect ( ( ) => {
44+ const handleKeyDown = ( e : KeyboardEvent ) => {
45+ if ( ( e . metaKey || e . ctrlKey ) && e . key === "f" ) {
46+ // Mark as keyboard triggered so handleFocus knows to open
47+ wasKeyboardTriggeredRef . current = true ;
48+ }
49+ } ;
50+
51+ document . addEventListener ( "keydown" , handleKeyDown ) ;
52+ return ( ) => {
53+ document . removeEventListener ( "keydown" , handleKeyDown ) ;
54+ } ;
55+ } , [ ] ) ;
56+
4057 // Track explicit clicks
4158 const handleMouseDown = useCallback ( ( ) => {
4259 wasClickedRef . current = true ;
4360 } , [ ] ) ;
4461
45- // Only open on explicit clicks, not programmatic focus
62+ // Open on explicit clicks or keyboard shortcut , not programmatic focus restoration
4663 const handleFocus = useCallback ( ( ) => {
47- if ( wasClickedRef . current ) {
64+ if ( wasClickedRef . current || wasKeyboardTriggeredRef . current ) {
4865 setIsOpen ( true ) ;
4966 wasClickedRef . current = false ;
67+ wasKeyboardTriggeredRef . current = false ;
5068 }
5169 } , [ ] ) ;
5270
0 commit comments