fix: modal footer should be hidden if null (#38138)

This commit is contained in:
MadCcc 2022-10-21 10:16:03 +08:00 committed by GitHub
parent a48bc3c466
commit 2453e21744
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 26 additions and 41 deletions

View File

@ -54,26 +54,26 @@ export function renderFooter(
footer,
} = props;
return (
footer ?? (
<LocaleReceiver componentName="Modal" defaultLocale={getConfirmLocale()}>
{locale => (
<>
<Button onClick={onCancel} {...cancelButtonProps}>
{cancelText || locale!.cancelText}
</Button>
<Button
{...convertLegacyProps(okType)}
loading={confirmLoading}
onClick={onOk}
{...okButtonProps}
>
{okText || locale!.okText}
</Button>
</>
)}
</LocaleReceiver>
)
return footer === undefined ? (
<LocaleReceiver componentName="Modal" defaultLocale={getConfirmLocale()}>
{locale => (
<>
<Button onClick={onCancel} {...cancelButtonProps}>
{cancelText || locale!.cancelText}
</Button>
<Button
{...convertLegacyProps(okType)}
loading={confirmLoading}
onClick={onOk}
{...okButtonProps}
>
{okText || locale!.okText}
</Button>
</>
)}
</LocaleReceiver>
) : (
footer
);
}

View File

@ -105,4 +105,9 @@ describe('Modal', () => {
errSpy.mockRestore();
});
it('should not render footer if null', () => {
const { container } = render(<Modal footer={null} />);
expect(container.querySelector('.ant-modal-footer')).toBeFalsy();
});
});

View File

@ -155,26 +155,6 @@ exports[`Modal render without footer 1`] = `
>
Here is content of Modal
</div>
<div
class="ant-modal-footer"
>
<button
class="ant-btn ant-btn-default"
type="button"
>
<span>
Cancel
</span>
</button>
<button
class="ant-btn ant-btn-primary"
type="button"
>
<span>
OK
</span>
</button>
</div>
</div>
<div
aria-hidden="true"

View File

@ -37,7 +37,7 @@ const genBaseStyle: GenerateStyle<PopconfirmToken> = token => {
flexWrap: 'nowrap',
alignItems: 'start',
[`> ${iconCls}`]: {
[`> ${componentCls}-message-icon ${iconCls}`]: {
color: colorWarning,
fontSize,
flex: 'none',