Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion react-common/components/controls/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,34 @@ export const Modal = (props: ModalProps) => {
className
);

const modalRef = React.useRef<HTMLDivElement>(null);

React.useEffect(() => {
const root = parentElement || document.body;
const parent = modalRef.current?.parentElement;

const hiddenSiblings: Element[] = [];

for (const child of root.children) {
if (child !== parent) {
if (!child.hasAttribute("aria-hidden") || child.getAttribute("aria-hidden") === "false") {
(child as HTMLElement).setAttribute("aria-hidden", "true");
hiddenSiblings.push(child);
}
}
}

return () => {
for (const child of hiddenSiblings) {
(child as HTMLElement).removeAttribute("aria-hidden");
}
};
}, [parentElement])

return ReactDOM.createPortal(<FocusTrap className={classes} onEscape={closeClickHandler}>
<div id={id}
className="common-modal"
ref={modalRef}
role={role || "dialog"}
aria-hidden={ariaHidden}
aria-label={ariaLabel}
Expand Down Expand Up @@ -131,5 +156,5 @@ export const Modal = (props: ModalProps) => {
</div>
}
</div>
</FocusTrap>, parentElement || document.getElementById("root") || document.body)
</FocusTrap>, parentElement || document.body)
}
Loading