fix(popConfirm): visible prop compatible (#45702)

* fix: visible compatible

* chore: add test

---------

Co-authored-by: linhf123 <wb-lhf780012@antgroup.com>
Co-authored-by: MadCcc <madccc@foxmail.com>
This commit is contained in:
@linhf2023 2023-11-08 13:34:54 +08:00 committed by GitHub
parent 5ac3f57b7c
commit 299592d9b7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 2 deletions

View File

@ -128,6 +128,38 @@ describe('Popconfirm', () => {
jest.useRealTimers(); jest.useRealTimers();
}); });
it('should be controlled by visible', () => {
jest.useFakeTimers();
const popconfirm = render(
<Popconfirm title="code">
<span>show me your code</span>
</Popconfirm>,
);
expect(popconfirm.container.querySelector('.ant-popover')).toBe(null);
popconfirm.rerender(
<Popconfirm title="code" visible>
<span>show me your code</span>
</Popconfirm>,
);
expect(popconfirm.container.querySelector('.ant-popover')).not.toBe(null);
expect(popconfirm.container.querySelector('.ant-popover')?.className).not.toContain(
'ant-popover-hidden',
);
popconfirm.rerender(
<Popconfirm title="code" visible={false}>
<span>show me your code</span>
</Popconfirm>,
);
act(() => {
jest.runAllTimers();
});
expect(popconfirm.container.querySelector('.ant-popover')).not.toBe(null);
jest.useRealTimers();
});
it('should trigger onConfirm and onCancel', async () => { it('should trigger onConfirm and onCancel', async () => {
const confirm = jest.fn(); const confirm = jest.fn();
const cancel = jest.fn(); const cancel = jest.fn();

View File

@ -54,8 +54,8 @@ const Popconfirm = React.forwardRef<TooltipRef, PopconfirmProps>((props, ref) =>
const { getPrefixCls } = React.useContext(ConfigContext); const { getPrefixCls } = React.useContext(ConfigContext);
const [open, setOpen] = useMergedState(false, { const [open, setOpen] = useMergedState(false, {
value: props.open, value: props.open ?? props.visible,
defaultValue: props.defaultOpen, defaultValue: props.defaultOpen ?? props.defaultVisible,
}); });
const settingOpen = ( const settingOpen = (