Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Support SVG elements on modals): expand utils for stacking order to include SVGElements #427

Merged
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,8 @@ function recalculateIntersectingHandles({
}) {
intersectingHandles.splice(0);

let targetElement: HTMLElement | null = null;
if (target instanceof HTMLElement) {
let targetElement: HTMLElement | SVGElement | null = null;
if (target instanceof HTMLElement || target instanceof SVGElement) {
targetElement = target;
}

Expand Down Expand Up @@ -212,7 +212,7 @@ function recalculateIntersectingHandles({
// It's not enough to compare only the target
// The target might be a small element inside of a larger container
// (For example, a SPAN or a DIV inside of a larger modal dialog)
let currentElement: HTMLElement | null = targetElement;
let currentElement: HTMLElement | SVGElement | null = targetElement;
let didIntersect = false;
while (currentElement) {
if (currentElement.contains(dragHandleElement)) {
Expand Down
24 changes: 12 additions & 12 deletions packages/react-resizable-panels/src/vendor/stacking-order.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import { assert } from "..";
/**
* Determine which of two nodes appears in front of the other —
* if `a` is in front, returns 1, otherwise returns -1
* @param {HTMLElement} a
* @param {HTMLElement} b
* @param {HTMLElement | SVGElement} a
* @param {HTMLElement | SVGElement} b
*/
export function compare(a: HTMLElement, b: HTMLElement): number {
export function compare(a: HTMLElement | SVGElement, b: HTMLElement | SVGElement): number {
if (a === b) throw new Error("Cannot compare node with itself");

const ancestors = {
Expand Down Expand Up @@ -60,15 +60,15 @@ export function compare(a: HTMLElement, b: HTMLElement): number {
const props =
/\b(?:position|zIndex|opacity|transform|webkitTransform|mixBlendMode|filter|webkitFilter|isolation)\b/;

/** @param {HTMLElement} node */
function is_flex_item(node: HTMLElement) {
/** @param {HTMLElement | SVGElement} node */
function is_flex_item(node: HTMLElement | SVGElement) {
// @ts-ignore
const display = getComputedStyle(get_parent(node) ?? node).display;
return display === "flex" || display === "inline-flex";
}

/** @param {HTMLElement} node */
function creates_stacking_context(node: HTMLElement) {
/** @param {HTMLElement | SVGElement} node */
function creates_stacking_context(node: HTMLElement | SVGElement) {
const style = getComputedStyle(node);

// https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Positioning/Understanding_z_index/The_stacking_context
Expand Down Expand Up @@ -98,8 +98,8 @@ function creates_stacking_context(node: HTMLElement) {
return false;
}

/** @param {HTMLElement[]} nodes */
function find_stacking_context(nodes: HTMLElement[]) {
/** @param {(HTMLElement| SVGElement)[]} nodes */
function find_stacking_context(nodes: (HTMLElement | SVGElement)[]) {
let i = nodes.length;

while (i--) {
Expand All @@ -111,13 +111,13 @@ function find_stacking_context(nodes: HTMLElement[]) {
return null;
}

/** @param {HTMLElement} node */
function get_z_index(node: HTMLElement | null) {
/** @param {HTMLElement | SVGElement} node */
function get_z_index(node: HTMLElement | SVGElement | null) {
return (node && Number(getComputedStyle(node).zIndex)) || 0;
}

/** @param {HTMLElement} node */
function get_ancestors(node: HTMLElement | null) {
function get_ancestors(node: HTMLElement | SVGElement | null) {
const ancestors = [];

while (node) {
Expand Down
Loading