Skip to content

Commit

Permalink
feat(Tooltip): fix dynamic width
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbrillant committed Apr 3, 2024
1 parent 045665e commit ec542a1
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 10 deletions.
4 changes: 0 additions & 4 deletions packages/react/src/components/tooltip/tooltip.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,6 @@ exports[`Tooltip Has default desktop styles (defaultOpen) 1`] = `
data-testid="tooltip-content-container"
id="uuid1"
isMobile={false}
key="1"
role="tooltip"
style={
{
Expand Down Expand Up @@ -493,7 +492,6 @@ exports[`Tooltip Has default desktop styles 1`] = `
data-testid="tooltip-content-container"
id="uuid1"
isMobile={false}
key="1"
role="tooltip"
style={
{
Expand Down Expand Up @@ -770,7 +768,6 @@ exports[`Tooltip Has mobile styles (defaultOpen) 1`] = `
data-testid="tooltip-content-container"
id="uuid1"
isMobile={true}
key="1"
role="tooltip"
style={
{
Expand Down Expand Up @@ -1043,7 +1040,6 @@ exports[`Tooltip Has mobile styles 1`] = `
data-testid="tooltip-content-container"
id="uuid1"
isMobile={true}
key="1"
role="tooltip"
style={
{
Expand Down
10 changes: 4 additions & 6 deletions packages/react/src/components/tooltip/tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -232,14 +232,9 @@ export const Tooltip: FunctionComponent<PropsWithChildren<TooltipProps>> = ({
const [tooltipTimeout, setTooltipTimeout] = useState<NodeJS.Timeout | undefined>();
const [controlledTooltipOpen, setControlledTooltipOpen] = useState<boolean>();
const [isClicked, setIsClicked] = useState<boolean>(false);
const [tooltipKey, setTooltipKey] = useState<number>(0);
const currentLabel = isClicked ? (confirmationLabel ?? label) : label;
const tooltipVariant = (mode === 'confirm' && isClicked) ? 'success' : 'normal';

useEffect(() => {
setTooltipKey((prevKey) => prevKey + 1);
}, [currentLabel]);

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

useEffect(() => {
popperTooltip.update?.();
}, [currentLabel, popperTooltip]);

const openTooltip = useCallback((): void => {
if (delayed && !disabled) {
setTooltipTimeout(() => setTimeout(() => setControlledTooltipOpen(true), titleDelay));
Expand Down Expand Up @@ -370,7 +369,6 @@ export const Tooltip: FunctionComponent<PropsWithChildren<TooltipProps>> = ({
isMobile={isMobile}
variant={tooltipVariant}
visible={popperTooltip.visible}
key={tooltipKey}
{...popperTooltip.getTooltipProps() /* eslint-disable-line react/jsx-props-no-spreading */}
>
<TooltipArrow
Expand Down

0 comments on commit ec542a1

Please sign in to comment.