Skip to content

Commit 739f17d

Browse files
Change how events are handled within Modal.jsx to reduce accidental closures
1 parent ab96b08 commit 739f17d

2 files changed

Lines changed: 13 additions & 5 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* Ensure that abnormally-shaped album art is still horizontally centered
66
* Add error handling on browser page for instances where the selected stream isn't browsable
77
* Add scrollbars to tall modals
8+
* Change how events are handled with Modals to reduce accidental closures
89
* System
910
* Make update process properly report errors
1011

web/src/components/Modal/Modal.jsx

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,24 @@
11
import React from "react";
2-
32
import "./Modal.scss";
43
import StopProp from "@/components/StopProp/StopProp";
5-
64
import PropTypes from "prop-types";
75

86
const Modal = ({ children, className = "", onClose }) => {
7+
const [mouseDownOutside, setMouseDownOutside] = React.useState(false);
98
return (
109
<div
1110
className={`modal_container ${className}`}
12-
onClick={(e) => {
13-
onClose();
14-
e.stopPropagation();
11+
onMouseDown={(e) => {
12+
if (e.target === e.currentTarget) {
13+
setMouseDownOutside(true);
14+
} else {
15+
setMouseDownOutside(false);
16+
}
17+
}}
18+
onMouseUp={(e) => {
19+
if (mouseDownOutside && e.target === e.currentTarget) {
20+
onClose();
21+
}
1522
}}
1623
>
1724
<StopProp>{children}</StopProp>

0 commit comments

Comments
 (0)