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';
1919import { useRangesData } from '../global/Providers/HistoryServiceProvider.js' ;
2020import { usePlatformName } from '../types.js' ;
2121import { useLayoutMode } from '../global/hooks/useLayoutMode.js' ;
22+ import { useClickAnywhereElse } from '../global/hooks/useClickAnywhereElse.jsx' ;
2223
2324export function App ( ) {
2425 const platformName = usePlatformName ( ) ;
@@ -39,6 +40,7 @@ export function App() {
3940 useURLReflection ( ) ;
4041 useSearchCommit ( ) ;
4142 useSearchCommitForRange ( ) ;
43+ const clickAnywhere = useClickAnywhereElse ( ) ;
4244
4345 /**
4446 * onClick can be passed directly to the main container,
@@ -62,7 +64,13 @@ export function App() {
6264 } , [ onKeyDown , query ] ) ;
6365
6466 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+ >
6674 < aside class = { styles . aside } >
6775 < Sidebar ranges = { ranges } />
6876 </ aside >
Original file line number Diff line number Diff line change @@ -99,11 +99,7 @@ export function useRowInteractions(mainRef) {
9999 if ( handled ) {
100100 event . preventDefault ( ) ;
101101 event . stopImmediatePropagation ( ) ;
102- } else {
103- console . log ( 'did not handle selection' ) ;
104102 }
105- } else {
106- dispatch ( { kind : 'reset' , reason : 'click occurred outside of rows' } ) ;
107103 }
108104 }
109105
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