Skip to content

Commit 299592d

Browse files
linhf123MadCcc
andauthored
fix(popConfirm): visible prop compatible (ant-design#45702)
* fix: visible compatible * chore: add test --------- Co-authored-by: linhf123 <[email protected]> Co-authored-by: MadCcc <[email protected]>
1 parent 5ac3f57 commit 299592d

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

components/popconfirm/__tests__/index.test.tsx

+32
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,38 @@ describe('Popconfirm', () => {
128128
jest.useRealTimers();
129129
});
130130

131+
it('should be controlled by visible', () => {
132+
jest.useFakeTimers();
133+
const popconfirm = render(
134+
<Popconfirm title="code">
135+
<span>show me your code</span>
136+
</Popconfirm>,
137+
);
138+
139+
expect(popconfirm.container.querySelector('.ant-popover')).toBe(null);
140+
popconfirm.rerender(
141+
<Popconfirm title="code" visible>
142+
<span>show me your code</span>
143+
</Popconfirm>,
144+
);
145+
146+
expect(popconfirm.container.querySelector('.ant-popover')).not.toBe(null);
147+
expect(popconfirm.container.querySelector('.ant-popover')?.className).not.toContain(
148+
'ant-popover-hidden',
149+
);
150+
151+
popconfirm.rerender(
152+
<Popconfirm title="code" visible={false}>
153+
<span>show me your code</span>
154+
</Popconfirm>,
155+
);
156+
act(() => {
157+
jest.runAllTimers();
158+
});
159+
expect(popconfirm.container.querySelector('.ant-popover')).not.toBe(null);
160+
jest.useRealTimers();
161+
});
162+
131163
it('should trigger onConfirm and onCancel', async () => {
132164
const confirm = jest.fn();
133165
const cancel = jest.fn();

components/popconfirm/index.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ const Popconfirm = React.forwardRef<TooltipRef, PopconfirmProps>((props, ref) =>
5454

5555
const { getPrefixCls } = React.useContext(ConfigContext);
5656
const [open, setOpen] = useMergedState(false, {
57-
value: props.open,
58-
defaultValue: props.defaultOpen,
57+
value: props.open ?? props.visible,
58+
defaultValue: props.defaultOpen ?? props.defaultVisible,
5959
});
6060

6161
const settingOpen = (

0 commit comments

Comments
 (0)