Skip to content

Commit

Permalink
fix(tooltip): fix bug with controlled state (#759)
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitrsavk committed Jul 23, 2021
1 parent 187bb0e commit dd0144e
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions packages/tooltip/src/Component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,10 @@ export const Tooltip: FC<TooltipProps> = ({
const contentRef = useRef<RefElement>(null);
const timer = useRef(0);

const show = forcedOpen === undefined ? visible : forcedOpen;

const open = () => {
if (!visible) {
if (!show) {
setVisible(true);

if (onOpen) {
Expand All @@ -163,17 +165,17 @@ export const Tooltip: FC<TooltipProps> = ({
};

const close = useCallback(() => {
if (visible) {
if (show) {
setVisible(false);

if (onClose) {
onClose();
}
}
}, [onClose, visible]);
}, [onClose, show]);

const toggle = () => {
if (visible) {
if (show) {
close();
} else {
open();
Expand Down Expand Up @@ -294,8 +296,6 @@ export const Tooltip: FC<TooltipProps> = ({
}
};

const show = forcedOpen === undefined ? visible : forcedOpen;

return (
<Fragment>
<div ref={mergeRefs([targetRef, setTarget])} {...getTargetProps()}>
Expand Down

0 comments on commit dd0144e

Please sign in to comment.