mirror of
https://github.com/ant-design/ant-design.git
synced 2024-11-24 02:59:58 +08:00
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:
parent
5ac3f57b7c
commit
299592d9b7
@ -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();
|
||||||
|
@ -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 = (
|
||||||
|
Loading…
Reference in New Issue
Block a user