mirror of
https://github.com/ant-design/ant-design.git
synced 2024-11-29 13:47:02 +08:00
fix: Fix icon set null
not hide icon (#37532)
* fix: Modal confirm can set icon to null * test: add test case
This commit is contained in:
parent
02f41204e7
commit
a8fc6e893a
@ -54,7 +54,9 @@ export function ConfirmContent(
|
||||
|
||||
// Icon
|
||||
let mergedIcon: React.ReactNode = icon;
|
||||
if (!icon) {
|
||||
|
||||
// 支持传入{ icon: null }来隐藏`Modal.confirm`默认的Icon
|
||||
if (!icon && icon !== null) {
|
||||
switch (type) {
|
||||
case 'info':
|
||||
mergedIcon = <InfoCircleFilled />;
|
||||
@ -73,7 +75,6 @@ export function ConfirmContent(
|
||||
}
|
||||
}
|
||||
|
||||
// 支持传入{ icon: null }来隐藏`Modal.confirm`默认的Icon
|
||||
const okType = props.okType || 'primary';
|
||||
// 默认为 true,保持向下兼容
|
||||
const mergedOkCancel = okCancel ?? type === 'confirm';
|
||||
|
@ -570,6 +570,28 @@ describe('Modal.confirm triggers callbacks correctly', () => {
|
||||
jest.useRealTimers();
|
||||
});
|
||||
|
||||
it('icon can be null to hide icon', async () => {
|
||||
jest.useFakeTimers();
|
||||
confirm({
|
||||
title: 'some title',
|
||||
content: 'some descriptions',
|
||||
icon: null,
|
||||
});
|
||||
|
||||
await act(async () => {
|
||||
jest.runAllTimers();
|
||||
await sleep();
|
||||
});
|
||||
|
||||
// We check icon is not exist in the body
|
||||
expect(document.querySelector('.ant-modal-confirm-body')!.children).toHaveLength(2);
|
||||
expect(
|
||||
document.querySelector('.ant-modal-confirm-body')!.querySelector('.anticon'),
|
||||
).toBeFalsy();
|
||||
|
||||
jest.useRealTimers();
|
||||
});
|
||||
|
||||
it('ok button should trigger onOk once when click it many times quickly', async () => {
|
||||
const onOk = jest.fn();
|
||||
open({ onOk });
|
||||
|
@ -262,7 +262,7 @@ const genModalConfirmStyle: GenerateStyle<ModalToken> = token => {
|
||||
alignItems: 'center',
|
||||
|
||||
[`${confirmComponentCls}-title`]: {
|
||||
flex: 1,
|
||||
flex: '0 0 100%',
|
||||
display: 'block',
|
||||
// create BFC to avoid
|
||||
// https://user-images.githubusercontent.com/507615/37702510-ba844e06-2d2d-11e8-9b67-8e19be57f445.png
|
||||
@ -276,6 +276,7 @@ const genModalConfirmStyle: GenerateStyle<ModalToken> = token => {
|
||||
[`${confirmComponentCls}-content`]: {
|
||||
color: token.colorText,
|
||||
fontSize: token.fontSizeBase,
|
||||
marginBlockStart: token.marginXS,
|
||||
},
|
||||
|
||||
[`> ${token.iconCls}`]: {
|
||||
@ -283,10 +284,13 @@ const genModalConfirmStyle: GenerateStyle<ModalToken> = token => {
|
||||
marginInlineEnd: token.marginSM,
|
||||
fontSize: token.modalConfirmIconSize,
|
||||
|
||||
[`+ ${confirmComponentCls}-title`]: {
|
||||
flex: 1,
|
||||
},
|
||||
|
||||
// `content` after `icon` should set marginLeft
|
||||
[`+ ${confirmComponentCls}-title + ${confirmComponentCls}-content`]: {
|
||||
marginInlineStart: token.modalConfirmIconSize + token.marginSM,
|
||||
marginBlockStart: token.marginXS,
|
||||
flexBasis: '100%',
|
||||
},
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user