diff --git a/.changeset/thick-fans-cheer.md b/.changeset/thick-fans-cheer.md new file mode 100644 index 00000000..af987d35 --- /dev/null +++ b/.changeset/thick-fans-cheer.md @@ -0,0 +1,5 @@ +--- +'@xyflow/react': patch +--- + +Forward ref of the div inside Panel components. diff --git a/packages/react/src/components/Panel/index.tsx b/packages/react/src/components/Panel/index.tsx index eeb01a15..83b4a87b 100644 --- a/packages/react/src/components/Panel/index.tsx +++ b/packages/react/src/components/Panel/index.tsx @@ -1,4 +1,4 @@ -import type { HTMLAttributes, ReactNode } from 'react'; +import { forwardRef, type HTMLAttributes, type ReactNode } from 'react'; import cc from 'classcat'; import type { PanelPosition } from '@xyflow/system'; @@ -15,17 +15,20 @@ export type PanelProps = HTMLAttributes & { const selector = (s: ReactFlowState) => (s.userSelectionActive ? 'none' : 'all'); -export function Panel({ position = 'top-left', children, className, style, ...rest }: PanelProps) { - const pointerEvents = useStore(selector); - const positionClasses = `${position}`.split('-'); +export const Panel = forwardRef( + ({ position = 'top-left', children, className, style, ...rest }, ref) => { + const pointerEvents = useStore(selector); + const positionClasses = `${position}`.split('-'); - return ( -
- {children} -
- ); -} + return ( +
+ {children} +
+ ); + } +);