Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(design): Modal should hide footer dom when footer is false #531

Merged
merged 1 commit into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion packages/design/src/modal/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import ConfigProvider from '../config-provider';
import { modal } from '../static-function';
import useStyle from './style';

const Modal = ({ prefixCls: customizePrefixCls, className, ...restProps }: ModalProps) => {
const Modal = ({ footer, prefixCls: customizePrefixCls, className, ...restProps }: ModalProps) => {
const { getPrefixCls } = useContext(ConfigProvider.ConfigContext);
const prefixCls = getPrefixCls('modal', customizePrefixCls);
const { wrapSSR } = useStyle(prefixCls);
Expand All @@ -15,6 +15,9 @@ const Modal = ({ prefixCls: customizePrefixCls, className, ...restProps }: Modal
return wrapSSR(
<AntModal
destroyOnClose={true}
// convert false to null to hide .ant-modal-footer dom
// ref: https://github.com/ant-design/ant-design/blob/master/components/modal/Modal.tsx#L105
footer={footer === false ? null : footer}
prefixCls={customizePrefixCls}
className={modalCls}
{...restProps}
Expand Down
179 changes: 179 additions & 0 deletions packages/design/src/modal/__tests__/__snapshots__/modal.test.tsx.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`Modal > should hide footer dom when footer is false 1`] = `
<div>
<div>
<div
class="ant-modal-root"
>
<div
class="ant-modal-mask"
/>
<div
class="ant-modal-wrap"
tabindex="-1"
>
<div
aria-labelledby="test-id"
aria-modal="true"
class="ant-modal ant-zoom-appear ant-zoom-appear-prepare ant-zoom"
role="dialog"
style="width: 520px;"
>
<div
aria-hidden="true"
style="width: 0px; height: 0px; overflow: hidden; outline: none;"
tabindex="0"
/>
<div
style="outline: none;"
tabindex="-1"
>
<div
class="ant-modal-content"
>
<button
aria-label="Close"
class="ant-modal-close"
type="button"
>
<span
class="ant-modal-close-x"
>
<span
aria-label="close"
class="anticon anticon-close ant-modal-close-icon"
role="img"
>
<svg
aria-hidden="true"
data-icon="close"
fill="currentColor"
fill-rule="evenodd"
focusable="false"
height="1em"
viewBox="64 64 896 896"
width="1em"
>
<path
d="M799.86 166.31c.02 0 .04.02.08.06l57.69 57.7c.04.03.05.05.06.08a.12.12 0 010 .06c0 .03-.02.05-.06.09L569.93 512l287.7 287.7c.04.04.05.06.06.09a.12.12 0 010 .07c0 .02-.02.04-.06.08l-57.7 57.69c-.03.04-.05.05-.07.06a.12.12 0 01-.07 0c-.03 0-.05-.02-.09-.06L512 569.93l-287.7 287.7c-.04.04-.06.05-.09.06a.12.12 0 01-.07 0c-.02 0-.04-.02-.08-.06l-57.69-57.7c-.04-.03-.05-.05-.06-.07a.12.12 0 010-.07c0-.03.02-.05.06-.09L454.07 512l-287.7-287.7c-.04-.04-.05-.06-.06-.09a.12.12 0 010-.07c0-.02.02-.04.06-.08l57.7-57.69c.03-.04.05-.05.07-.06a.12.12 0 01.07 0c.03 0 .05.02.09.06L512 454.07l287.7-287.7c.04-.04.06-.05.09-.06a.12.12 0 01.07 0z"
/>
</svg>
</span>
</span>
</button>
<div
class="ant-modal-header"
>
<div
class="ant-modal-title"
id="test-id"
>
This is title
</div>
</div>
<div
class="ant-modal-body"
/>
</div>
</div>
<div
aria-hidden="true"
style="width: 0px; height: 0px; overflow: hidden; outline: none;"
tabindex="0"
/>
</div>
</div>
</div>
</div>
</div>
`;

exports[`Modal > should hide footer dom when footer is null 1`] = `
<div>
<div>
<div
class="ant-modal-root"
>
<div
class="ant-modal-mask"
/>
<div
class="ant-modal-wrap"
tabindex="-1"
>
<div
aria-labelledby="test-id"
aria-modal="true"
class="ant-modal ant-zoom-appear ant-zoom-appear-prepare ant-zoom"
role="dialog"
style="width: 520px;"
>
<div
aria-hidden="true"
style="width: 0px; height: 0px; overflow: hidden; outline: none;"
tabindex="0"
/>
<div
style="outline: none;"
tabindex="-1"
>
<div
class="ant-modal-content"
>
<button
aria-label="Close"
class="ant-modal-close"
type="button"
>
<span
class="ant-modal-close-x"
>
<span
aria-label="close"
class="anticon anticon-close ant-modal-close-icon"
role="img"
>
<svg
aria-hidden="true"
data-icon="close"
fill="currentColor"
fill-rule="evenodd"
focusable="false"
height="1em"
viewBox="64 64 896 896"
width="1em"
>
<path
d="M799.86 166.31c.02 0 .04.02.08.06l57.69 57.7c.04.03.05.05.06.08a.12.12 0 010 .06c0 .03-.02.05-.06.09L569.93 512l287.7 287.7c.04.04.05.06.06.09a.12.12 0 010 .07c0 .02-.02.04-.06.08l-57.7 57.69c-.03.04-.05.05-.07.06a.12.12 0 01-.07 0c-.03 0-.05-.02-.09-.06L512 569.93l-287.7 287.7c-.04.04-.06.05-.09.06a.12.12 0 01-.07 0c-.02 0-.04-.02-.08-.06l-57.69-57.7c-.04-.03-.05-.05-.06-.07a.12.12 0 010-.07c0-.03.02-.05.06-.09L454.07 512l-287.7-287.7c-.04-.04-.05-.06-.06-.09a.12.12 0 010-.07c0-.02.02-.04.06-.08l57.7-57.69c.03-.04.05-.05.07-.06a.12.12 0 01.07 0c.03 0 .05.02.09.06L512 454.07l287.7-287.7c.04-.04.06-.05.09-.06a.12.12 0 01.07 0z"
/>
</svg>
</span>
</span>
</button>
<div
class="ant-modal-header"
>
<div
class="ant-modal-title"
id="test-id"
>
This is title
</div>
</div>
<div
class="ant-modal-body"
/>
</div>
</div>
<div
aria-hidden="true"
style="width: 0px; height: 0px; overflow: hidden; outline: none;"
tabindex="0"
/>
</div>
</div>
</div>
</div>
</div>
`;
38 changes: 38 additions & 0 deletions packages/design/src/modal/__tests__/modal.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import React, { useEffect } from 'react';
import { render } from '@testing-library/react';
import { Modal } from '@oceanbase/design';
import type { ModalProgressProps } from '@oceanbase/design/es/modal';

const ModalTest: React.FC<ModalProgressProps> = props => {
const [open, setOpen] = React.useState(false);
const container = React.useRef<HTMLDivElement>(null);
useEffect(() => {
setOpen(true);
}, []);
return (
<div>
<div ref={container} />
<Modal
title="This is title"
description="This is description"
open={open}
getContainer={container.current!}
{...props}
/>
</div>
);
};

describe('Modal', () => {
it('should hide footer dom when footer is null', () => {
const { container, asFragment } = render(<ModalTest footer={null} />);
expect(container.querySelector('.ant-modal-footer')).toBeFalsy();
expect(asFragment().firstChild).toMatchSnapshot();
});

it('should hide footer dom when footer is false', () => {
const { container, asFragment } = render(<ModalTest footer={false} />);
expect(container.querySelector('.ant-modal-footer')).toBeFalsy();
expect(asFragment().firstChild).toMatchSnapshot();
});
});
Loading