Skip to content

Commit fda2233

Browse files
authored
feat(Support SVG elements on modals): expand utils for stacking order to include SVGElements (#427)
The issue: When hovering over SVG icons on elements "above" a handle (e.g. modal) the resize cursor appears and users can drag it to resize the panels "bellow". Suggested solution: Expand the `recalculateIntersectingHandles` function to include `SVGElement` when looking at the stacking order of elements which fire pointer events.
1 parent 030795a commit fda2233

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

packages/react-resizable-panels/src/PanelResizeHandleRegistry.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,8 @@ function recalculateIntersectingHandles({
167167
}) {
168168
intersectingHandles.splice(0);
169169

170-
let targetElement: HTMLElement | null = null;
171-
if (target instanceof HTMLElement) {
170+
let targetElement: HTMLElement | SVGElement | null = null;
171+
if (target instanceof HTMLElement || target instanceof SVGElement) {
172172
targetElement = target;
173173
}
174174

@@ -212,7 +212,7 @@ function recalculateIntersectingHandles({
212212
// It's not enough to compare only the target
213213
// The target might be a small element inside of a larger container
214214
// (For example, a SPAN or a DIV inside of a larger modal dialog)
215-
let currentElement: HTMLElement | null = targetElement;
215+
let currentElement: HTMLElement | SVGElement | null = targetElement;
216216
let didIntersect = false;
217217
while (currentElement) {
218218
if (currentElement.contains(dragHandleElement)) {

packages/react-resizable-panels/src/vendor/stacking-order.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ import { assert } from "..";
77
/**
88
* Determine which of two nodes appears in front of the other —
99
* if `a` is in front, returns 1, otherwise returns -1
10-
* @param {HTMLElement} a
11-
* @param {HTMLElement} b
10+
* @param {HTMLElement | SVGElement} a
11+
* @param {HTMLElement | SVGElement} b
1212
*/
13-
export function compare(a: HTMLElement, b: HTMLElement): number {
13+
export function compare(a: HTMLElement | SVGElement, b: HTMLElement | SVGElement): number {
1414
if (a === b) throw new Error("Cannot compare node with itself");
1515

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

63-
/** @param {HTMLElement} node */
64-
function is_flex_item(node: HTMLElement) {
63+
/** @param {HTMLElement | SVGElement} node */
64+
function is_flex_item(node: HTMLElement | SVGElement) {
6565
// @ts-ignore
6666
const display = getComputedStyle(get_parent(node) ?? node).display;
6767
return display === "flex" || display === "inline-flex";
6868
}
6969

70-
/** @param {HTMLElement} node */
71-
function creates_stacking_context(node: HTMLElement) {
70+
/** @param {HTMLElement | SVGElement} node */
71+
function creates_stacking_context(node: HTMLElement | SVGElement) {
7272
const style = getComputedStyle(node);
7373

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

101-
/** @param {HTMLElement[]} nodes */
102-
function find_stacking_context(nodes: HTMLElement[]) {
101+
/** @param {(HTMLElement| SVGElement)[]} nodes */
102+
function find_stacking_context(nodes: (HTMLElement | SVGElement)[]) {
103103
let i = nodes.length;
104104

105105
while (i--) {
@@ -111,13 +111,13 @@ function find_stacking_context(nodes: HTMLElement[]) {
111111
return null;
112112
}
113113

114-
/** @param {HTMLElement} node */
115-
function get_z_index(node: HTMLElement | null) {
114+
/** @param {HTMLElement | SVGElement} node */
115+
function get_z_index(node: HTMLElement | SVGElement | null) {
116116
return (node && Number(getComputedStyle(node).zIndex)) || 0;
117117
}
118118

119119
/** @param {HTMLElement} node */
120-
function get_ancestors(node: HTMLElement | null) {
120+
function get_ancestors(node: HTMLElement | SVGElement | null) {
121121
const ancestors = [];
122122

123123
while (node) {

0 commit comments

Comments
 (0)