@turnit-ou/shared 2.18.1 → 2.18.3
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 +22 -4
- 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,28 @@ 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 event that mounted it. This one
|
|
72
|
+
// stays mounted while closed, so a drawer opened from a mouseup handler
|
|
73
|
+
// would receive that same mouseup as an outside click and close 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
|
-
|
|
88
|
+
const isNonPrimaryButton = 'button' in event && event.button !== 0;
|
|
89
|
+
if (clickAwayArmedRef.current && !isNonPrimaryButton) {
|
|
73
90
|
onClose?.(event, 'backdropClick');
|
|
74
|
-
|
|
91
|
+
}
|
|
92
|
+
}, [onClose]);
|
|
75
93
|
const classes = useStyles({ width, ...props });
|
|
76
94
|
// The drawer is a modal: MUI moves focus into it on open, keeps it there
|
|
77
95
|
// while it is open and puts it back on close. The page behind it is hidden
|
|
@@ -79,7 +97,7 @@ export function DrawerForm(inProps) {
|
|
|
79
97
|
// why MUI's own aria-hidden is not enough here).
|
|
80
98
|
const drawerRef = useRef(null);
|
|
81
99
|
useInertBackground(Boolean(open), drawerRef);
|
|
82
|
-
return (_jsx(ClickAwayListener, { onClickAway: handleClickAway, children: _jsx(Drawer, { ref: drawerRef, anchor: "right", open: open, onClose: onClose, className: classNames(classes.modal, className), disablePortal: true, hideBackdrop: true, PaperProps: {
|
|
100
|
+
return (_jsx(ClickAwayListener, { mouseEvent: "onMouseUp", onClickAway: handleClickAway, children: _jsx(Drawer, { ref: drawerRef, anchor: "right", open: open, onClose: onClose, className: classNames(classes.modal, className), disablePortal: true, hideBackdrop: true, PaperProps: {
|
|
83
101
|
className: classes.paper,
|
|
84
102
|
elevation: 4,
|
|
85
103
|
square: true,
|