Skip to content

Commit

Permalink
fix(tooltip): group useState declarations and rename variable to mult…
Browse files Browse the repository at this point in the history
…ipleFocusEvents
  • Loading branch information
ddoemonn committed Oct 1, 2024
1 parent 5cd39de commit 1287449
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions components/lib/tooltip/Tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const Tooltip = React.memo(
const [visibleState, setVisibleState] = React.useState(false);
const [positionState, setPositionState] = React.useState(props.position || 'right');
const [classNameState, setClassNameState] = React.useState('');
const [multipleFocusEvents, setMultipleFocusEvents] = React.useState(false);
const metaData = {
props,
state: {
Expand All @@ -29,8 +30,6 @@ export const Tooltip = React.memo(
}
};

const [isBothFocus, setIsBothFocus] = React.useState(false);

const { ptm, cx, sx, isUnstyled } = TooltipBase.setMetaData(metaData);

useHandleStyle(TooltipBase.css.styles, isUnstyled, { name: 'tooltip' });
Expand Down Expand Up @@ -112,7 +111,7 @@ export const Tooltip = React.memo(

if (event === 'both') {
showEvents = ['focus', 'mouseenter'];
hideEvents = isBothFocus ? ['blur'] : ['mouseleave', 'blur'];
hideEvents = multipleFocusEvents ? ['blur'] : ['mouseleave', 'blur'];
}
}

Expand Down Expand Up @@ -174,7 +173,7 @@ export const Tooltip = React.memo(
};

const show = (e) => {
if(e.type && e.type==="focus") setIsBothFocus(true);
if(e.type && e.type==="focus") setMultipleFocusEvents(true);

currentTargetRef.current = e.currentTarget;
const disabled = isDisabled(currentTargetRef.current);
Expand Down Expand Up @@ -202,7 +201,7 @@ export const Tooltip = React.memo(
};

const hide = (e) => {
if(e && e.type==="blur") setIsBothFocus(false);
if(e && e.type==="blur") setMultipleFocusEvents(false);

clearTimeouts();

Expand Down

0 comments on commit 1287449

Please sign in to comment.