File tree Expand file tree Collapse file tree
packages/react-resizable-panels/src/utils/dom Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import { isHTMLElement } from "./isHTMLElement" ;
2+
13export function getPanelGroupElement (
24 id : string ,
35 rootElement : ParentNode | HTMLElement = document
46) : HTMLElement | null {
5- //If the root element is the PanelGroup
6- if (
7- rootElement instanceof HTMLElement &&
8- ( rootElement as HTMLElement ) ?. dataset ?. panelGroupId == id
9- ) {
7+ // If the root element is the PanelGroup
8+ if ( isHTMLElement ( rootElement ) && rootElement . dataset . panelGroupId == id ) {
109 return rootElement as HTMLElement ;
1110 }
1211
13- //Else query children
12+ // Else query children
1413 const element = rootElement . querySelector (
1514 `[data-panel-group][data-panel-group-id="${ id } "]`
1615 ) ;
Original file line number Diff line number Diff line change 1+ export function isHTMLElement ( target : unknown ) : target is HTMLElement {
2+ if ( target instanceof HTMLElement ) {
3+ return true ;
4+ }
5+
6+ // Fallback to duck typing to handle edge case of portals within a popup window
7+ return (
8+ typeof target === "object" &&
9+ target !== null &&
10+ "tagName" in target &&
11+ "getAttribute" in target
12+ ) ;
13+ }
You can’t perform that action at this time.
0 commit comments