@@ -12,7 +12,7 @@ import "./InfoBox.scss";
1212const TRANSITION_SPEED = 500 ;
1313
1414export default function InfoBox ( { desc, displayMode, title, url } ) {
15- const [ hidden , setHidden ] = useState ( true ) ;
15+ const [ closed , setClosed ] = useState ( true ) ;
1616
1717 const ref = useRef ( null ) ;
1818
@@ -22,45 +22,70 @@ export default function InfoBox({ desc, displayMode, title, url }) {
2222
2323 if ( ! height || ! intro ) return ;
2424
25- if ( hidden ) {
25+ if ( closed ) {
2626 intro . style . transition = "margin 300ms" ;
2727 intro . style . marginBottom = "80px" ; // .leaflet-bottom .leaflet-control in App.scss
2828 } else {
2929 intro . style . transition = "margin 300ms 200ms" ;
3030 intro . style . marginBottom = `${ height + 64 } px` ;
3131 }
32- } , [ hidden ] ) ;
32+ } , [ closed ] ) ;
33+
34+ const setKeyboardUser = ( e ) => {
35+ const body = document . body ;
36+
37+ if ( e . keyCode === 9 ) {
38+ body . classList . add ( "using-keyboard" ) ;
39+ }
40+ } ;
41+
42+ useEffect ( ( ) => {
43+ const map = document . getElementsByClassName ( "leaflet-container" ) [ 0 ] ;
44+
45+ map . addEventListener ( "keyup" , setKeyboardUser ) ;
46+
47+ return ( ) => {
48+ map . removeEventListener ( "keyup" , setKeyboardUser ) ;
49+ } ;
50+ } , [ ] ) ;
3351
3452 useEffect ( ( ) => {
3553 const body = document . body ;
3654 body . classList . add ( "overflow-hidden" ) ;
3755
3856 const map = document . getElementsByClassName ( "leaflet-container" ) [ 0 ] ;
3957
40- const handleClick = ( ) => {
41- setHidden ( ! hidden ) ;
58+ const handleMapClick = ( ) => {
59+ setClosed ( ! closed ) ;
4260 } ;
4361
44- if ( hidden ) {
45- map . removeEventListener ( "click" , handleClick ) ;
46- map . removeEventListener ( "touchstart" , handleClick ) ;
47- map . removeEventListener ( "touchmove" , handleClick ) ;
48- return ;
62+ if ( closed ) {
63+ document . querySelector ( ".leaflet-container" ) . focus ( ) ;
64+ map . removeEventListener ( "click" , handleMapClick ) ;
65+ map . removeEventListener ( "touchstart" , handleMapClick ) ;
66+ map . removeEventListener ( "touchmove" , handleMapClick ) ;
67+ return undefined ;
4968 }
5069
5170 window . setTimeout ( ( ) => {
52- map . addEventListener ( "click" , handleClick ) ;
53- map . addEventListener ( "touchstart" , handleClick ) ;
54- map . addEventListener ( "touchmove" , handleClick ) ;
71+ map . addEventListener ( "click" , handleMapClick ) ;
72+ map . addEventListener ( "touchstart" , handleMapClick ) ;
73+ map . addEventListener ( "touchmove" , handleMapClick ) ;
5574 } , 100 ) ;
56- } , [ hidden ] ) ;
75+
76+ return ( ) => {
77+ map . removeEventListener ( "click" , handleMapClick ) ;
78+ map . removeEventListener ( "touchstart" , handleMapClick ) ;
79+ map . removeEventListener ( "touchmove" , handleMapClick ) ;
80+ } ;
81+ } , [ closed ] ) ;
5782
5883 return (
59- < CSSTransition in = { ! hidden } timeout = { TRANSITION_SPEED } >
84+ < CSSTransition in = { ! closed } timeout = { TRANSITION_SPEED } >
6085 < div >
6186 < InfoButton
6287 displayMode = { displayMode }
63- handleClick = { ( ) => setHidden ( ! hidden ) }
88+ handleClick = { ( ) => setClosed ( ! closed ) }
6489 />
6590 < div ref = { ref } className = { classNames ( "info-wrapper" , displayMode ) } >
6691 < div className = "info-title" >
0 commit comments