Skip to content

Commit

Permalink
fix(popConfirm): visible prop compatible (ant-design#45702)
Browse files Browse the repository at this point in the history
* fix: visible compatible

* chore: add test

---------

Co-authored-by: linhf123 <[email protected]>
Co-authored-by: MadCcc <[email protected]>
  • Loading branch information
3 people authored Nov 8, 2023
1 parent 5ac3f57 commit 299592d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
32 changes: 32 additions & 0 deletions components/popconfirm/__tests__/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,38 @@ describe('Popconfirm', () => {
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 () => {
const confirm = jest.fn();
const cancel = jest.fn();
Expand Down
4 changes: 2 additions & 2 deletions components/popconfirm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ const Popconfirm = React.forwardRef<TooltipRef, PopconfirmProps>((props, ref) =>

const { getPrefixCls } = React.useContext(ConfigContext);
const [open, setOpen] = useMergedState(false, {
value: props.open,
defaultValue: props.defaultOpen,
value: props.open ?? props.visible,
defaultValue: props.defaultOpen ?? props.defaultVisible,
});

const settingOpen = (
Expand Down

0 comments on commit 299592d

Please sign in to comment.