Skip to content

Commit

Permalink
Implemented new utility function for finding highest zIndex in ancestors
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenthoms committed Oct 20, 2021
1 parent 1e96853 commit 55b1962
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ import React, { Component, Fragment, MouseEvent } from "react";
import ReactDOM from "react-dom";
import classNames from "classnames";
import PropTypes from "prop-types";
import "./Suggestions.css";

import TreeNodeSelection from "../utils/TreeNodeSelection";
import { TreeDataNodeMetaData } from "../utils/TreeDataNodeTypes";
import { findHighestZIndex } from "../../../utils/dom";

import "./Suggestions.css";

type SuggestionsProps = {
suggestionsRef: React.RefObject<HTMLDivElement>;
Expand Down Expand Up @@ -418,9 +421,7 @@ class Suggestions extends Component<SuggestionsProps> {
};

const zIndex = this.positionRef.current
? parseInt(
window.getComputedStyle(this.positionRef.current, null).zIndex
)
? findHighestZIndex(this.positionRef.current) + 1
: 99;

ReactDOM.render(
Expand Down
14 changes: 14 additions & 0 deletions react/src/lib/utils/dom.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export const findHighestZIndex = (element: Element): number => {
let currentElement: Element | null = element;
let highestZIndex = 0;
while (currentElement) {
const currentZIndex = parseInt(
window.getComputedStyle(currentElement, null).zIndex
);
if (!isNaN(currentZIndex)) {
highestZIndex = Math.max(highestZIndex, currentZIndex);
}
currentElement = currentElement.parentElement;
}
return highestZIndex;
};

0 comments on commit 55b1962

Please sign in to comment.