File tree Expand file tree Collapse file tree 3 files changed +27
-5
lines changed
special-pages/pages/history/app Expand file tree Collapse file tree 3 files changed +27
-5
lines changed Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ import { useSearchCommit } from '../global/hooks/useSearchCommit.js';
19
19
import { useRangesData } from '../global/Providers/HistoryServiceProvider.js' ;
20
20
import { usePlatformName } from '../types.js' ;
21
21
import { useLayoutMode } from '../global/hooks/useLayoutMode.js' ;
22
+ import { useClickAnywhereElse } from '../global/hooks/useClickAnywhereElse.jsx' ;
22
23
23
24
export function App ( ) {
24
25
const platformName = usePlatformName ( ) ;
@@ -39,6 +40,7 @@ export function App() {
39
40
useURLReflection ( ) ;
40
41
useSearchCommit ( ) ;
41
42
useSearchCommitForRange ( ) ;
43
+ const clickAnywhere = useClickAnywhereElse ( ) ;
42
44
43
45
/**
44
46
* onClick can be passed directly to the main container,
@@ -62,7 +64,13 @@ export function App() {
62
64
} , [ onKeyDown , query ] ) ;
63
65
64
66
return (
65
- < div class = { styles . layout } data-theme = { isDarkMode ? 'dark' : 'light' } data-platform = { platformName } data-layout-mode = { mode } >
67
+ < div
68
+ class = { styles . layout }
69
+ data-theme = { isDarkMode ? 'dark' : 'light' }
70
+ data-platform = { platformName }
71
+ data-layout-mode = { mode }
72
+ onClick = { clickAnywhere }
73
+ >
66
74
< aside class = { styles . aside } >
67
75
< Sidebar ranges = { ranges } />
68
76
</ aside >
Original file line number Diff line number Diff line change @@ -99,11 +99,7 @@ export function useRowInteractions(mainRef) {
99
99
if ( handled ) {
100
100
event . preventDefault ( ) ;
101
101
event . stopImmediatePropagation ( ) ;
102
- } else {
103
- console . log ( 'did not handle selection' ) ;
104
102
}
105
- } else {
106
- dispatch ( { kind : 'reset' , reason : 'click occurred outside of rows' } ) ;
107
103
}
108
104
}
109
105
Original file line number Diff line number Diff line change
1
+ import { useSelectionDispatch } from '../Providers/SelectionProvider.js' ;
2
+ import { useCallback } from 'preact/hooks' ;
3
+
4
+ /**
5
+ * Custom hook that creates a callback function to handle click events occurring outside of specified elements.
6
+ * The callback dispatches a reset action when the click event target is not a button or an anchor element.
7
+ */
8
+ export function useClickAnywhereElse ( ) {
9
+ const dispatch = useSelectionDispatch ( ) ;
10
+ return useCallback (
11
+ ( e ) => {
12
+ if ( e . target ?. closest ?. ( 'button,a' ) === null ) {
13
+ dispatch ( { kind : 'reset' , reason : 'click occurred outside of rows' } ) ;
14
+ }
15
+ } ,
16
+ [ dispatch ] ,
17
+ ) ;
18
+ }
You can’t perform that action at this time.
0 commit comments