@@ -2,8 +2,8 @@ import React, {
22 HTMLAttributes ,
33 CSSProperties ,
44 FC ,
5- useRef ,
65 ReactNode ,
6+ forwardRef ,
77} from 'react' ;
88import classnames from 'classnames' ;
99import {
@@ -60,9 +60,10 @@ export type PopoverProps = {
6060/**
6161 *
6262 */
63- export const PopoverInner : FC < PopoverProps & AutoAlignInjectedProps > = (
64- props
65- ) => {
63+ export const PopoverInner = forwardRef <
64+ HTMLDivElement ,
65+ PopoverProps & AutoAlignInjectedProps
66+ > ( ( props , ref ) => {
6667 const {
6768 children,
6869 alignment,
@@ -73,7 +74,6 @@ export const PopoverInner: FC<PopoverProps & AutoAlignInjectedProps> = (
7374 bodyStyle,
7475 ...rprops
7576 } = props ;
76- const elRef = useRef < HTMLDivElement | null > ( null ) ;
7777 const nubbinPosition = alignment . join ( '-' ) ;
7878 const [ firstAlign , secondAlign ] = alignment ;
7979 const popoverClassNames = classnames (
@@ -103,7 +103,7 @@ export const PopoverInner: FC<PopoverProps & AutoAlignInjectedProps> = (
103103 } ;
104104 return (
105105 < div
106- ref = { elRef }
106+ ref = { ref }
107107 className = { popoverClassNames }
108108 role = { tooltip ? 'tooltip' : 'dialog' }
109109 style = { rootStyle }
@@ -112,22 +112,26 @@ export const PopoverInner: FC<PopoverProps & AutoAlignInjectedProps> = (
112112 < PopoverBody style = { bodyStyle } > { children } </ PopoverBody >
113113 </ div >
114114 ) ;
115- } ;
115+ } ) ;
116116
117117/**
118118 *
119119 */
120- export const Popover : FC < PopoverProps > = ( { position, ...props } ) => {
121- const alignment : RectangleAlignment | undefined = position ?. split ( '-' ) as
122- | RectangleAlignment
123- | undefined ;
124- return (
125- < AutoAlign
126- triggerSelector = '.slds-dropdown-trigger'
127- alignmentStyle = 'popover'
128- alignment = { alignment }
129- >
130- { ( injectedProps ) => < PopoverInner { ...props } { ...injectedProps } /> }
131- </ AutoAlign >
132- ) ;
133- } ;
120+ export const Popover = forwardRef < HTMLDivElement , PopoverProps > (
121+ ( { position, ...props } , ref ) => {
122+ const alignment : RectangleAlignment | undefined = position ?. split ( '-' ) as
123+ | RectangleAlignment
124+ | undefined ;
125+ return (
126+ < AutoAlign
127+ triggerSelector = '.slds-dropdown-trigger'
128+ alignmentStyle = 'popover'
129+ alignment = { alignment }
130+ >
131+ { ( injectedProps ) => (
132+ < PopoverInner { ...props } { ...injectedProps } ref = { ref } />
133+ ) }
134+ </ AutoAlign >
135+ ) ;
136+ }
137+ ) ;
0 commit comments