Skip to content

Commit a41926c

Browse files
committed
Merge branch 'focus-trap' of Arnei/opencast-admin-interface into r/17.x
Pull request #1339 Fixes #600 Add focus trap to modal
2 parents cda7f04 + 33457c0 commit a41926c

3 files changed

Lines changed: 49 additions & 24 deletions

File tree

package-lock.json

Lines changed: 26 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"classnames": "^2.5.1",
1616
"date-fns": "^4.1.0",
1717
"dompurify": "^3.2.5",
18+
"focus-trap-react": "^11.0.4",
1819
"font-awesome": "^4.7.0",
1920
"formik": "^2.4.6",
2021
"http-proxy-middleware": "^3.0.5",

src/components/shared/modals/Modal.tsx

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@ import { useHotkeys } from "react-hotkeys-hook";
44
import { availableHotkeys } from "../../../configs/hotkeysConfig";
55
import { useTranslation } from "react-i18next";
66
import ButtonLikeAnchor from "../ButtonLikeAnchor";
7-
// TODO: Implement focus trapping
8-
// Attempted to do that with focus-trap-react, but it would not focus
9-
// the correct element in e.g. the new event modal
10-
// import { FocusTrap } from "focus-trap-react";
7+
import { FocusTrap } from "focus-trap-react";
118

129
export type ModalProps = {
1310
open?: boolean
@@ -63,26 +60,28 @@ export const Modal = forwardRef<ModalHandle, PropsWithChildren<ModalProps>>(({
6360

6461
return ReactDOM.createPortal(
6562
isOpen &&
66-
<div>
67-
<div className="modal-animation modal-overlay" />
68-
<section
69-
id={classId}
70-
className={className ? className : "modal wizard modal-animation"}
71-
>
72-
<header>
73-
<ButtonLikeAnchor
74-
extraClassName="fa fa-times close-modal"
75-
onClick={close}
76-
tabIndex={0}
77-
/>
78-
<h2>
79-
{header}
80-
</h2>
81-
</header>
63+
<FocusTrap>
64+
<div>
65+
<div className="modal-animation modal-overlay" />
66+
<section
67+
id={classId}
68+
className={className ? className : "modal wizard modal-animation"}
69+
>
70+
<header>
71+
<ButtonLikeAnchor
72+
extraClassName="fa fa-times close-modal"
73+
onClick={close}
74+
tabIndex={0}
75+
/>
76+
<h2>
77+
{header}
78+
</h2>
79+
</header>
8280

83-
{children}
84-
</section>
85-
</div>,
81+
{children}
82+
</section>
83+
</div>
84+
</FocusTrap>,
8685
document.body,
8786
);
8887

0 commit comments

Comments
 (0)