Skip to content

Commit 49e3414

Browse files
committed
Pass ref in PopupButton component
1 parent c2d577c commit 49e3414

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/components/PopupButton/index.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export interface PopupButtonProps<N extends number | string | undefined> extends
1919
persistent: boolean;
2020
arrowHidden?: boolean;
2121
defaultShown?: boolean;
22+
elementRef?: React.RefObject<HTMLButtonElement>;
2223
}
2324
function PopupButton<N extends number | string | undefined>(props: PopupButtonProps<N>) {
2425
const {
@@ -32,12 +33,15 @@ function PopupButton<N extends number | string | undefined>(props: PopupButtonPr
3233
arrowHidden,
3334
persistent,
3435
defaultShown,
36+
elementRef,
3537
...otherProps
3638
} = props;
3739

38-
const buttonRef = React.useRef<HTMLButtonElement>(null);
40+
const internalButtonRef = React.useRef<HTMLButtonElement>(null);
3941
const popupRef = React.useRef<HTMLDivElement>(null);
4042

43+
const buttonRef = elementRef ?? internalButtonRef;
44+
4145
const [popupShown, setPopupShown] = React.useState(defaultShown ?? false);
4246

4347
useEffect(

0 commit comments

Comments
 (0)