Skip to content

Commit

Permalink
TPP 849 fix modal and popover z index issues (#311)
Browse files Browse the repository at this point in the history
  • Loading branch information
KitoC authored Aug 5, 2024
1 parent f56618c commit f4c5605
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 8 deletions.
13 changes: 11 additions & 2 deletions lib/components/ActionsMenu/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ import {
FloatingPortal,
useMergeRefs
} from "@floating-ui/react";
import {
getFloatingUiRootElement,
getFloatingUiZIndex
} from "../../utils/floatingUiHelpers";

const ActionMenuContext = createContext({});

Expand Down Expand Up @@ -314,14 +318,19 @@ export const ActionsMenuBody = ({
{triggerComponent}

{actionMenu.context.open && (
<FloatingPortal>
<FloatingPortal
root={getFloatingUiRootElement(actionMenu.refs.reference)}
>
<FloatingFocusManager
context={actionMenu.context}
modal={actionMenu.modal}
>
<div
ref={ref}
style={{ ...actionMenu.floatingStyles, zIndex: 1100 }}
style={{
...actionMenu.floatingStyles,
zIndex: getFloatingUiZIndex(actionMenu.refs.reference)
}}
aria-labelledby={actionMenu.labelId}
{...actionMenu.getFloatingProps(props)}
className="actionMenu-content"
Expand Down
7 changes: 6 additions & 1 deletion lib/components/Modal/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,12 @@ const Modal = ({
>
{visible && (
<FocusTrap focusTrapOptions={{ onDeactivate: onClose }}>
<div role="dialog" aria-modal="true" aria-label={ariaLabel}>
<div
id="modal"
role="dialog"
aria-modal="true"
aria-label={ariaLabel}
>
<Container
width={width}
height={height}
Expand Down
14 changes: 12 additions & 2 deletions lib/components/Popover/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ import styled from "styled-components";
import Icon from "../Icon";
import { PropTypes } from "prop-types";
import Box from "../Box";
import {
getFloatingUiRootElement,
getFloatingUiZIndex
} from "../../utils/floatingUiHelpers";

const DIRECTIONS_MAP = {
topLeft: "top-start",
Expand Down Expand Up @@ -330,12 +334,18 @@ export default function Popover({
<Box {...props}>
{triggerComponent}

<FloatingPortal preserveTabOrder={true}>
<FloatingPortal
root={getFloatingUiRootElement(context.refs.reference)}
preserveTabOrder={true}
>
{text && (
<StyledPopoverContainer
className={`Tooltip popover ${visible ? "visible" : ""}`}
ref={refs.setFloating}
style={{ ...floatingStyles, zIndex: 1100 }}
style={{
...floatingStyles,
zIndex: getFloatingUiZIndex(context.refs.reference)
}}
{...getFloatingProps()}
>
<FloatingFocusManager
Expand Down
27 changes: 27 additions & 0 deletions lib/utils/floatingUiHelpers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const getFloatingUiZIndex = (triggerRef) => {
const activeModalRef = document.getElementById("modal-overlay");

if (
activeModalRef &&
triggerRef.current &&
activeModalRef?.contains?.(triggerRef.current)
) {
return 1100;
}

return 900;
};

const getFloatingUiRootElement = (triggerRef) => {
const activeModalRef = document.getElementById("modal-overlay");

const isRenderedInModal = activeModalRef?.contains?.(triggerRef.current);

if (isRenderedInModal) {
return document.getElementById("modal");
}

return undefined;
};

export { getFloatingUiZIndex, getFloatingUiRootElement };
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "orcs-design-system",
"version": "3.2.16",
"version": "3.2.17",
"engines": {
"node": "20.12.2"
},
Expand Down

0 comments on commit f4c5605

Please sign in to comment.