mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Dropdown: Fixes double call to onVisibilityChange (#87607)
* Dropdown: Fixes double call to onVisibilityChange * Update * update
This commit is contained in:
@@ -10,7 +10,7 @@ import {
|
||||
useFloating,
|
||||
useInteractions,
|
||||
} from '@floating-ui/react';
|
||||
import React, { useEffect, useRef, useState } from 'react';
|
||||
import React, { useCallback, useRef, useState } from 'react';
|
||||
import { CSSTransition } from 'react-transition-group';
|
||||
|
||||
import { GrafanaTheme2 } from '@grafana/data';
|
||||
@@ -34,9 +34,13 @@ export const Dropdown = React.memo(({ children, overlay, placement, offset, onVi
|
||||
const [show, setShow] = useState(false);
|
||||
const transitionRef = useRef(null);
|
||||
|
||||
useEffect(() => {
|
||||
onVisibleChange?.(show);
|
||||
}, [onVisibleChange, show]);
|
||||
const handleOpenChange = useCallback(
|
||||
(newState: boolean) => {
|
||||
setShow(newState);
|
||||
onVisibleChange?.(newState);
|
||||
},
|
||||
[onVisibleChange]
|
||||
);
|
||||
|
||||
// the order of middleware is important!
|
||||
const middleware = [
|
||||
@@ -56,7 +60,7 @@ export const Dropdown = React.memo(({ children, overlay, placement, offset, onVi
|
||||
const { context, refs, floatingStyles } = useFloating({
|
||||
open: show,
|
||||
placement: getPlacement(placement),
|
||||
onOpenChange: setShow,
|
||||
onOpenChange: handleOpenChange,
|
||||
middleware,
|
||||
whileElementsMounted: autoUpdate,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user