Skip to content

Commit

Permalink
fix: tooltip is-ellipsis not working
Browse files Browse the repository at this point in the history
  • Loading branch information
siam-ese committed Jun 19, 2024
1 parent f59ab40 commit 5df9851
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions packages/design/src/components/tooltip/Tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import type { TooltipRef } from 'rc-tooltip';
import RcTooltip from 'rc-tooltip';
import React, { forwardRef, useContext, useImperativeHandle, useRef } from 'react';
import React, { forwardRef, useCallback, useContext, useImperativeHandle, useRef, useState } from 'react';

import { ConfigContext } from '../config-provider/ConfigProvider';
import styles from './index.module.less';
Expand Down Expand Up @@ -53,14 +53,22 @@ export const Tooltip = forwardRef<NullableTooltipRef, ITooltipProps>((props, ref
} = props;

const { mountContainer } = useContext(ConfigContext);
const [tooltipEl, setTooltipEl] = useState<HTMLElement>();
const tooltipRef = useRef<NullableTooltipRef>(null);
const refHandler = useCallback((ref: TooltipRef | null) => {
if (ref?.nativeElement) {
setTooltipEl(ref.nativeElement);
}
tooltipRef.current = ref;
}, []);
useImperativeHandle<NullableTooltipRef, NullableTooltipRef>(ref, () => tooltipRef.current);

const isEllipsis = useIsEllipsis(showIfEllipsis ? tooltipRef.current?.nativeElement : null);
const isEllipsis = useIsEllipsis(showIfEllipsis ? tooltipEl : null);

return mountContainer && (
<RcTooltip
visible={(showIfEllipsis && !isEllipsis) ? false : visible}
ref={tooltipRef}
ref={refHandler}
prefixCls={styles.tooltip}
getTooltipContainer={() => mountContainer}
overlay={<div className={styles.tooltipContent}>{typeof title === 'function' ? title() : title}</div>}
Expand Down

0 comments on commit 5df9851

Please sign in to comment.