@turnit-ou/shared 2.18.1 → 2.18.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/components/DrawerForm.js +20 -3
- package/package.json +1 -1
package/components/DrawerForm.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { useCallback, useRef } from 'react';
|
|
2
|
+
import { useCallback, useEffect, useRef } from 'react';
|
|
3
3
|
import { makeStyles, useTheme } from '@mui/styles';
|
|
4
4
|
import Paper from '@mui/material/Paper';
|
|
5
5
|
import ClickAwayListener from '@mui/material/ClickAwayListener';
|
|
@@ -68,10 +68,27 @@ export function DrawerForm(inProps) {
|
|
|
68
68
|
const handleClickClose = useCallback((event) => {
|
|
69
69
|
onClose?.(event, 'close');
|
|
70
70
|
}, [onClose]);
|
|
71
|
+
// MUI's ClickAwayListener only skips the click that mounted it. This one
|
|
72
|
+
// stays mounted while closed, so the click that opens the drawer would also
|
|
73
|
+
// reach it as a click outside and close the drawer straight away.
|
|
74
|
+
const clickAwayArmedRef = useRef(false);
|
|
75
|
+
useEffect(() => {
|
|
76
|
+
if (!open) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
const timeout = setTimeout(() => {
|
|
80
|
+
clickAwayArmedRef.current = true;
|
|
81
|
+
});
|
|
82
|
+
return () => {
|
|
83
|
+
clearTimeout(timeout);
|
|
84
|
+
clickAwayArmedRef.current = false;
|
|
85
|
+
};
|
|
86
|
+
}, [open]);
|
|
71
87
|
const handleClickAway = useCallback((event) => {
|
|
72
|
-
if (
|
|
88
|
+
if (clickAwayArmedRef.current) {
|
|
73
89
|
onClose?.(event, 'backdropClick');
|
|
74
|
-
|
|
90
|
+
}
|
|
91
|
+
}, [onClose]);
|
|
75
92
|
const classes = useStyles({ width, ...props });
|
|
76
93
|
// The drawer is a modal: MUI moves focus into it on open, keeps it there
|
|
77
94
|
// while it is open and puts it back on close. The page behind it is hidden
|