Skip to content

Commit f58284e

Browse files
authored
Add click handler to mouseDown on confirm button (#385)
1 parent 861e9a9 commit f58284e

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/components/confirm-buttons.tsx

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,16 @@ export function ConfirmButton(props: {
1919
const [clicked, setClicked] = useState(false);
2020
const [confirmed, setConfirmed] = useState(false);
2121

22+
// For Safari compatibility, also apply this to the "mouseDown" event, since the
23+
// "click" event doesn't fire when the user clicks or taps on a button made visible
24+
// in this way
25+
const clickHandler = (e: any) => {
26+
props.onConfirm();
27+
if (props.remainAfterConfirmation) {
28+
setConfirmed(true);
29+
}
30+
};
31+
2232
return (
2333
<Box sx={{ width: '6em' }}>
2434
{clicked ? (
@@ -29,12 +39,8 @@ export function ConfirmButton(props: {
2939
variant="contained"
3040
color="error"
3141
title={props.name}
32-
onClick={_ => {
33-
props.onConfirm();
34-
if (props.remainAfterConfirmation) {
35-
setConfirmed(true);
36-
}
37-
}}
42+
onClick={clickHandler}
43+
onMouseDown={clickHandler}
3844
onBlur={_ => setClicked(false)}
3945
style={{ visibility: clicked ? 'visible' : 'hidden' }}
4046
autoFocus

0 commit comments

Comments
 (0)