Prevent closing modal on click inside
[MAILPOET-2602]
This commit is contained in:
committed by
Jack Kitterhing
parent
91bce97ab4
commit
bf9ddc10cb
@@ -1,4 +1,4 @@
|
|||||||
import React from 'react';
|
import React, { useRef } from 'react';
|
||||||
import classnames from 'classnames';
|
import classnames from 'classnames';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
|
|
||||||
@@ -16,6 +16,7 @@ function ModalFrame({
|
|||||||
role,
|
role,
|
||||||
style,
|
style,
|
||||||
}) {
|
}) {
|
||||||
|
const wrapperRef = useRef(null);
|
||||||
function onClose(event) {
|
function onClose(event) {
|
||||||
if (onRequestClose) {
|
if (onRequestClose) {
|
||||||
onRequestClose(event);
|
onRequestClose(event);
|
||||||
@@ -23,7 +24,10 @@ function ModalFrame({
|
|||||||
}
|
}
|
||||||
|
|
||||||
function handleFocusOutside(event) {
|
function handleFocusOutside(event) {
|
||||||
if (shouldCloseOnClickOutside) {
|
if (shouldCloseOnClickOutside
|
||||||
|
&& wrapperRef.current
|
||||||
|
&& !wrapperRef.current.contains(event.target) // filter clicks inside the modal window
|
||||||
|
) {
|
||||||
onClose(event);
|
onClose(event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -53,6 +57,7 @@ function ModalFrame({
|
|||||||
tabIndex="0"
|
tabIndex="0"
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
|
ref={wrapperRef}
|
||||||
className={classnames(
|
className={classnames(
|
||||||
'mailpoet-modal-frame',
|
'mailpoet-modal-frame',
|
||||||
className
|
className
|
||||||
|
@@ -64,7 +64,7 @@ const FormPreview = () => {
|
|||||||
)}
|
)}
|
||||||
{form !== null && (
|
{form !== null && (
|
||||||
<div>
|
<div>
|
||||||
<style type="text/css" id="mailpoet_form_preview_styles">
|
<style type="text/css">
|
||||||
{'.mailpoet_hp_email_label { display: none }' }
|
{'.mailpoet_hp_email_label { display: none }' }
|
||||||
{form.css}
|
{form.css}
|
||||||
</style>
|
</style>
|
||||||
|
Reference in New Issue
Block a user