File tree 1 file changed +14
-8
lines changed
xp-archive/client/versionSelector/SlidePanel
1 file changed +14
-8
lines changed Original file line number Diff line number Diff line change 1
- import { useEffect } from 'react' ;
1
+ import { useEffect , useRef } from 'react' ;
2
2
import { createPortal } from 'react-dom' ;
3
3
import style from './SlidePanel.module.css' ;
4
4
@@ -9,21 +9,27 @@ type SlidePanelProps = {
9
9
} ;
10
10
11
11
export const SlidePanel = ( { isOpen, onClose, children } : SlidePanelProps ) => {
12
+ const dialogRef = useRef < HTMLDialogElement > ( null ) ;
13
+
12
14
useEffect ( ( ) => {
13
- const handleEscape = ( e : KeyboardEvent ) => {
14
- if ( e . key === 'Escape' ) onClose ( ) ;
15
- } ;
16
- document . addEventListener ( 'keydown' , handleEscape ) ;
17
- return ( ) => document . removeEventListener ( 'keydown' , handleEscape ) ;
18
- } , [ onClose ] ) ;
15
+ const dialog = dialogRef . current ;
16
+ if ( ! dialog ) return ;
17
+
18
+ if ( isOpen ) {
19
+ dialog . showModal ( ) ;
20
+ } else {
21
+ dialog . close ( ) ;
22
+ }
23
+ } , [ isOpen ] ) ;
19
24
20
25
if ( ! isOpen ) return null ;
21
26
22
27
return createPortal (
23
28
< dialog
29
+ ref = { dialogRef }
24
30
className = { style . overlay }
25
- open = { isOpen }
26
31
onClose = { onClose }
32
+ aria-modal = "true"
27
33
aria-label = "Version selector"
28
34
>
29
35
< button
You can’t perform that action at this time.
0 commit comments