Skip to content

Commit

Permalink
feat(Tooltip): fix dynamic width (#778)
Browse files Browse the repository at this point in the history
* feat(Tooltip): fix dynamic width

* feat(Tooltip): fix dynamic width

* feat(Tooltip): remove dynamic text story

* feat(Tooltip): update tooltip when label changes using useRef
  • Loading branch information
alexbrillant authored and mmorin-equisoft committed Apr 17, 2024
1 parent 64e6445 commit ffd94da
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions packages/react/src/components/tooltip/tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
PropsWithChildren,
useCallback,
useEffect,
useRef,
useMemo,
useState,
} from 'react';
Expand Down Expand Up @@ -234,6 +235,7 @@ export const Tooltip: FunctionComponent<PropsWithChildren<TooltipProps>> = ({
const [isClicked, setIsClicked] = useState<boolean>(false);
const currentLabel = isClicked ? (confirmationLabel ?? label) : label;
const tooltipVariant = (mode === 'confirm' && isClicked) ? 'success' : 'normal';
const prevLabel = useRef(currentLabel);

const getTooltipTriggerType = useCallback((): TriggerType | null => {
if (disabled) {
Expand All @@ -254,6 +256,11 @@ export const Tooltip: FunctionComponent<PropsWithChildren<TooltipProps>> = ({
delayShow: delayed ? titleDelay : undefined,
}, { modifiers });

if (prevLabel.current !== currentLabel) {
prevLabel.current = currentLabel;
popperTooltip?.update?.();
}

const openTooltip = useCallback((): void => {
if (delayed && !disabled) {
setTooltipTimeout(() => setTimeout(() => setControlledTooltipOpen(true), titleDelay));
Expand Down

0 comments on commit ffd94da

Please sign in to comment.