File tree Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Original file line number Diff line number Diff line change 1- import { useState } from 'react'
1+ import { useState , useEffect , useRef } from 'react'
22import styles from './MapOptions.module.css'
33import { MapOptionsStoreState } from '@/stores/MapOptionsStore'
44import Dispatcher from '@/stores/Dispatcher'
@@ -9,8 +9,22 @@ import * as config from 'config'
99
1010export default function ( props : MapOptionsStoreState ) {
1111 const [ isOpen , setIsOpen ] = useState ( false )
12+ const containerRef = useRef < HTMLDivElement > ( null )
13+ useEffect ( ( ) => {
14+ function handleClickOutside ( event : MouseEvent ) {
15+ if ( containerRef . current && ! containerRef . current . contains ( event . target as Node ) ) {
16+ setIsOpen ( false )
17+ }
18+ }
19+
20+ document . addEventListener ( 'mousedown' , handleClickOutside )
21+ return ( ) => {
22+ document . removeEventListener ( 'mousedown' , handleClickOutside )
23+ }
24+ } , [ ] )
1225 return (
1326 < div
27+ ref = { containerRef }
1428 className = { styles . mapOptionsContainer }
1529 onMouseEnter = { ( ) => setIsOpen ( true ) }
1630 onMouseLeave = { ( ) => setIsOpen ( false ) }
You can’t perform that action at this time.
0 commit comments