File tree Expand file tree Collapse file tree 1 file changed +20
-4
lines changed
src/pages/AccountLiveLocation/components/LayerSelector Expand file tree Collapse file tree 1 file changed +20
-4
lines changed Original file line number Diff line number Diff line change 1- import React from 'react'
1+ import React , { useRef , useEffect } from 'react'
22import classNames from 'classnames'
33import { Icon } from './../../../Generic'
44import styles from './LayerSelector.module.scss'
@@ -14,17 +14,33 @@ const LayerSelector = ({
1414 const [ showMenu , setShowMenu ] = React . useState ( false )
1515 const [ height , setHeight ] = React . useState ( 0 )
1616
17+ const handleState = ( ) => {
18+ setShowMenu ( false )
19+ setHeight ( 0 )
20+ }
21+
1722 const handleClick = e => {
18- if ( e . target . parentElement . value ) {
19- setShowMenu ( false )
20- setHeight ( 0 )
23+ if ( ! layerSelectorEl . current . contains ( e . target ) ) {
24+ //handleOutsideClick
25+ handleState ( )
26+ return
27+ } else {
28+ //handleInsideClick
29+ handleState ( )
2130 setSelectedMapLayer ( {
2231 type : e . target . parentElement . value ,
2332 data : e . target . parentElement . getAttribute ( 'data-layer' )
2433 } )
2534 }
2635 }
2736
37+ useEffect ( ( ) => {
38+ document . addEventListener ( 'mousedown' , handleClick , false )
39+ return ( ) => document . removeEventListener ( 'mousedown' , handleClick , false )
40+ } , [ ] )
41+
42+ const layerSelectorEl = useRef ( null )
43+
2844 return (
2945 < div
3046 className = { classNames ( styles . LayerSelectorContainer , {
You can’t perform that action at this time.
0 commit comments