From 02f38032659494117581cc3c4bdfe32631a66194 Mon Sep 17 00:00:00 2001 From: Aleksandr Gumroian Date: Mon, 16 Sep 2024 17:59:21 +0200 Subject: [PATCH 1/3] Refactor Modal component to use useFocusTrap hook --- src/bootstrap/Modal.js | 13 ++++++++----- src/utils/hooks.js | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 5 deletions(-) diff --git a/src/bootstrap/Modal.js b/src/bootstrap/Modal.js index aee202b..a1e65c0 100644 --- a/src/bootstrap/Modal.js +++ b/src/bootstrap/Modal.js @@ -9,7 +9,7 @@ import React, { useRef, useEffect } from "react"; import PropTypes from "prop-types"; -import { useClickOutside } from "../utils/hooks"; +import { useClickOutside, useFocusTrap } from "../utils/hooks"; import Portal from "../utils/Portal"; import "./Modal.css"; @@ -29,10 +29,11 @@ Modal.propTypes = { }; export function Modal({ shown, setShown, scrollable, size, children }) { - const dialogRef = useRef(); + const modalRef = useRef(); let modalSize = "modal-"; - useClickOutside(dialogRef, () => setShown(false)); + useClickOutside(modalRef, () => setShown(false)); + useFocusTrap(modalRef, shown); useEffect(() => { const handleEsc = (event) => { @@ -65,11 +66,13 @@ export function Modal({ shown, setShown, scrollable, size, children }) { return (
-
{title}
+

{title}