Skip to content
Snippets Groups Projects
Commit 4ffca789 authored by David Bühler's avatar David Bühler
Browse files

Merge branch 'feature/ivette/modal' into 'master'

[Ivette] added event to close modal with escape

See merge request frama-c/frama-c!4892
parents 90f380dd cf26eafa
No related branches found
No related tags found
No related merge requests found
...@@ -336,10 +336,21 @@ export function Modal( ...@@ -336,10 +336,21 @@ export function Modal(
const { label, title, icon, className, onClose, children } = props; const { label, title, icon, className, onClose, children } = props;
const contentClasses = classes('dome-xModal-content', className); const contentClasses = classes('dome-xModal-content', className);
const onCloseModal = (): void => { const onCloseModal = React.useCallback((): void => {
closeModal(); closeModal();
if(onClose) onClose(); if(onClose) onClose();
}; }, [onClose]);
React.useEffect(() => {
const handleKeyDown = (event: KeyboardEvent): void => {
if (event.key === "Escape") onCloseModal();
};
window.addEventListener("keydown", handleKeyDown);
return () => {
window.removeEventListener("keydown", handleKeyDown);
};
}, [onCloseModal]);
return ( return (
<div className={contentClasses}> <div className={contentClasses}>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment