Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,5 @@ package-lock.json
.dumi/tmp
.dumi/tmp-production

bun.lockb
bun.lockb
.vscode/
23 changes: 10 additions & 13 deletions src/Tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ export interface TooltipProps
> {
trigger?: ActionType | ActionType[];
defaultVisible?: boolean;
visible?: boolean;
open?: boolean;
placement?: string;
/** Config popup motion */
motion?: TriggerProps['popupMotion'];
onVisibleChange?: (visible: boolean) => void;
afterVisibleChange?: (visible: boolean) => void;
onOpenChange?: (open: boolean) => void;
afterOpenChange?: (open: boolean) => void;
overlay: (() => React.ReactNode) | React.ReactNode;
/** @deprecated Please use `styles={{ root: {} }}` */
overlayStyle?: React.CSSProperties;
Expand Down Expand Up @@ -68,8 +68,8 @@ const Tooltip = (props: TooltipProps, ref: React.Ref<TooltipRef>) => {
overlayStyle,
prefixCls = 'rc-tooltip',
children,
onVisibleChange,
afterVisibleChange,
onOpenChange,
afterOpenChange,
motion,
placement = 'right',
align = {},
Expand All @@ -83,6 +83,7 @@ const Tooltip = (props: TooltipProps, ref: React.Ref<TooltipRef>) => {
showArrow = true,
classNames: tooltipClassNames,
styles: tooltipStyles,
open,
...restProps
} = props;

Expand All @@ -91,11 +92,6 @@ const Tooltip = (props: TooltipProps, ref: React.Ref<TooltipRef>) => {

useImperativeHandle(ref, () => triggerRef.current);

const extraProps: Partial<TooltipProps & TriggerProps> = { ...restProps };
if ('visible' in props) {
extraProps.popupVisible = props.visible;
}

const getPopupElement = () => (
<Popup
key="content"
Expand Down Expand Up @@ -131,16 +127,17 @@ const Tooltip = (props: TooltipProps, ref: React.Ref<TooltipRef>) => {
ref={triggerRef}
popupAlign={align}
getPopupContainer={getTooltipContainer}
onPopupVisibleChange={onVisibleChange}
afterPopupVisibleChange={afterVisibleChange}
onOpenChange={onOpenChange}
afterOpenChange={afterOpenChange}
popupMotion={motion}
defaultPopupVisible={defaultVisible}
autoDestroy={destroyTooltipOnHide}
mouseLeaveDelay={mouseLeaveDelay}
popupStyle={{ ...overlayStyle, ...tooltipStyles?.root }}
mouseEnterDelay={mouseEnterDelay}
arrow={showArrow}
{...extraProps}
popupVisible={open}
{...restProps}
>
{getChildren()}
</Trigger>
Expand Down
4 changes: 2 additions & 2 deletions tests/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ describe('rc-tooltip', () => {
const App = () => {
const [open, setOpen] = React.useState(false);
return (
<Tooltip overlay={<strong className="x-content">Tooltip content</strong>} visible={open}>
<Tooltip overlay={<strong className="x-content">Tooltip content</strong>} open={open}>
<div
className="target"
onClick={() => {
Expand Down Expand Up @@ -263,7 +263,7 @@ describe('rc-tooltip', () => {
};

const { container } = render(
<Tooltip classNames={customClassNames} overlay={<div />} styles={customStyles} visible>
<Tooltip classNames={customClassNames} overlay={<div />} styles={customStyles} open>
<button />
</Tooltip>,
);
Expand Down
Loading