Commit cd5a14c 1 parent 00f5d80 commit cd5a14c Copy full SHA for cd5a14c
File tree 1 file changed +7
-3
lines changed
packages/orbit-components/src/Drawer
1 file changed +7
-3
lines changed Original file line number Diff line number Diff line change @@ -62,14 +62,18 @@ const Drawer = ({
62
62
63
63
React . useEffect ( ( ) => {
64
64
const handleKeyDown = ( event : KeyboardEvent ) => {
65
- if ( event . key === "Escape" && onClose ) {
65
+ if ( shown && event . key === "Escape" && onClose ) {
66
66
onClose ( ) ;
67
67
}
68
68
} ;
69
69
70
70
document . addEventListener ( "keydown" , handleKeyDown ) ;
71
71
return ( ) => document . removeEventListener ( "keydown" , handleKeyDown ) ;
72
- } , [ onClose ] ) ;
72
+ } , [ onClose , shown ] ) ;
73
+
74
+ const handleClickOutside = React . useCallback ( ( ) => {
75
+ if ( shown && onClose ) onClose ( ) ;
76
+ } , [ shown , onClose ] ) ;
73
77
74
78
const vars = {
75
79
"--lm-drawer-width" : width ,
@@ -80,7 +84,7 @@ const Drawer = ({
80
84
const onlyIcon = ! title && ! actions ;
81
85
const bordered = ! ! ( title || actions ) ;
82
86
83
- useClickOutside ( drawerRef , ( ) => onClose ?. ( ) ) ;
87
+ useClickOutside ( drawerRef , handleClickOutside ) ;
84
88
85
89
return (
86
90
< >
You can’t perform that action at this time.
0 commit comments