Skip to content
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
@@ -1,16 +1,15 @@
import { isHTMLElement } from "./isHTMLElement";

export function getPanelGroupElement(
id: string,
rootElement: ParentNode | HTMLElement = document
): HTMLElement | null {
//If the root element is the PanelGroup
if (
rootElement instanceof HTMLElement &&
(rootElement as HTMLElement)?.dataset?.panelGroupId == id
) {
// If the root element is the PanelGroup
if (isHTMLElement(rootElement) && rootElement.dataset.panelGroupId == id) {
return rootElement as HTMLElement;
}

//Else query children
// Else query children
const element = rootElement.querySelector(
`[data-panel-group][data-panel-group-id="${id}"]`
);
Expand Down
13 changes: 13 additions & 0 deletions packages/react-resizable-panels/src/utils/dom/isHTMLElement.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export function isHTMLElement(target: unknown): target is HTMLElement {
if (target instanceof HTMLElement) {
return true;
}

// Fallback to duck typing to handle edge case of portals within a popup window
return (
typeof target === "object" &&
target !== null &&
"tagName" in target &&
"getAttribute" in target
);
}