Close flash message when a modal is opened (#3711)

This commit is contained in:
Luke Heath
2022-01-16 20:46:20 -06:00
committed by GitHub
parent 61b21df79e
commit afaecee662
3 changed files with 14 additions and 3 deletions
+1
View File
@@ -0,0 +1 @@
* Close flash message when modal opens
@@ -1,5 +1,4 @@
import React, { useEffect, useState } from "react";
import PropTypes from "prop-types";
import classnames from "classnames";
import { INotifications } from "interfaces/notification";
@@ -28,7 +27,7 @@ const FlashMessage = ({
isPersistent,
onRemoveFlash,
onUndoActionClick,
}: IFlashMessage) => {
}: IFlashMessage): JSX.Element | null => {
const { alertType, isVisible, message, undoAction } = notification;
const klass = classnames(baseClass, `${baseClass}--${alertType}`, {
[`${baseClass}--full-width`]: fullWidth,
+12 -1
View File
@@ -1,5 +1,8 @@
import React, { useEffect } from "react";
import { useDispatch } from "react-redux";
import classnames from "classnames";
// @ts-ignore
import { hideFlash } from "redux/nodes/notifications/actions";
const baseClass = "modal";
@@ -10,7 +13,13 @@ export interface IModalProps {
className?: string;
}
const Modal = ({ children, onExit, title, className }: IModalProps) => {
const Modal = ({
children,
onExit,
title,
className,
}: IModalProps): JSX.Element => {
const dispatch = useDispatch();
useEffect(() => {
const closeWithEscapeKey = (e: KeyboardEvent) => {
if (e.key === "Escape") {
@@ -18,6 +27,8 @@ const Modal = ({ children, onExit, title, className }: IModalProps) => {
}
};
dispatch(hideFlash);
document.addEventListener("keydown", closeWithEscapeKey);
return () => {