mirror of
https://gitlab.nic.cz/turris/reforis/foris-js.git
synced 2024-12-24 00:01:36 +01:00
Add closing bootstrap modal using ESC
This commit is contained in:
parent
bdc8726791
commit
913a7d7b75
|
@ -1,11 +1,11 @@
|
|||
/*
|
||||
* Copyright (C) 2019 CZ.NIC z.s.p.o. (http://www.nic.cz/)
|
||||
* Copyright (C) 2020 CZ.NIC z.s.p.o. (http://www.nic.cz/)
|
||||
*
|
||||
* This is free software, licensed under the GNU General Public License v3.
|
||||
* See /LICENSE for more information.
|
||||
*/
|
||||
|
||||
import React, { useRef } from "react";
|
||||
import React, { useRef, useEffect } from "react";
|
||||
import PropTypes from "prop-types";
|
||||
|
||||
import { Portal } from "../utils/Portal";
|
||||
|
@ -31,6 +31,19 @@ export function Modal({ shown, setShown, scrollable, children }) {
|
|||
|
||||
useClickOutside(dialogRef, () => setShown(false));
|
||||
|
||||
useEffect(() => {
|
||||
const handleEsc = (event) => {
|
||||
if (event.keyCode === 27) {
|
||||
setShown(false);
|
||||
}
|
||||
};
|
||||
window.addEventListener("keydown", handleEsc);
|
||||
|
||||
return () => {
|
||||
window.removeEventListener("keydown", handleEsc);
|
||||
};
|
||||
}, [setShown]);
|
||||
|
||||
return (
|
||||
<Portal containerId="modal-container">
|
||||
<div className={`modal fade ${shown ? "show" : ""}`} role="dialog">
|
||||
|
|
Loading…
Reference in New Issue
Block a user