Skip to content

Commit

Permalink
Tooltip Both Fix with Dynamic State (primefaces#7288)
Browse files Browse the repository at this point in the history
* fix(tooltip): both fix with dynamic state

* fix(tooltip): syntax error

* fix(tooltip): group useState declarations and rename variable to multipleFocusEvents
  • Loading branch information
ddoemonn authored Oct 1, 2024
1 parent 5d9098e commit 9d76a74
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion 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 Down Expand Up @@ -110,7 +111,7 @@ export const Tooltip = React.memo(

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

Expand Down Expand Up @@ -172,6 +173,8 @@ export const Tooltip = React.memo(
};

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

currentTargetRef.current = e.currentTarget;
const disabled = isDisabled(currentTargetRef.current);
const empty = isContentEmpty(isShowOnDisabled(currentTargetRef.current) && disabled ? currentTargetRef.current.firstChild : currentTargetRef.current);
Expand All @@ -198,6 +201,8 @@ export const Tooltip = React.memo(
};

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

clearTimeouts();

if (visibleState) {
Expand Down

0 comments on commit 9d76a74

Please sign in to comment.