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(layout): remove extra dom node #3631

Merged
merged 5 commits into from
Sep 9, 2021
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
47 changes: 27 additions & 20 deletions packages/layout/src/components/PageContainer/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { PageHeader, Tabs, Affix, ConfigProvider, Breadcrumb } from 'antd';
import type { ReactNode } from 'react';
import React, { useContext } from 'react';
import React, { useContext, useMemo } from 'react';
import classNames from 'classnames';
import type {
TabsProps,
Expand Down Expand Up @@ -215,11 +215,16 @@ const ProPageHeader: React.FC<PageContainerProps & { prefixedClassName: string }
const { breadcrumb } = pageHeaderProps as {
breadcrumb: BreadcrumbProps;
};
const noHasBreadCrumb =
!breadcrumb ||
breadcrumbRender === false ||
(!breadcrumb?.itemRender && !breadcrumb?.routes?.length);

if (
['title', 'subTitle', 'breadcrumb', 'extra', 'tags', 'footer', 'avatar', 'backIcon'].every(
['title', 'subTitle', 'extra', 'tags', 'footer', 'avatar', 'backIcon'].every(
(item) => !pageHeaderProps[item],
) &&
(!breadcrumb || (!breadcrumb?.itemRender && !breadcrumb?.routes?.length)) &&
noHasBreadCrumb &&
!content &&
!extraContent
) {
Expand Down Expand Up @@ -267,20 +272,21 @@ const PageContainer: React.FC<PageContainerProps> = (props) => {
[`${prefixCls}-page-container-with-footer`]: footer,
});

const content = children ? (
<div>
<div className={`${prefixedClassName}-children-content`}>{children}</div>
{value.hasFooterToolbar && (
<div
style={{
height: 48,
marginTop: 24,
}}
/>
)}
</div>
) : null;

const content = useMemo(() => {
return children ? (
<>
<div className={`${prefixedClassName}-children-content`}>{children}</div>
{value.hasFooterToolbar && (
<div
style={{
height: 48,
marginTop: 24,
}}
/>
)}
</>
) : null;
}, [children, prefixedClassName, value.hasFooterToolbar]);
const pageHeaderDom = (
<ProPageHeader
{...restProps}
Expand All @@ -290,14 +296,15 @@ const PageContainer: React.FC<PageContainerProps> = (props) => {
/>
);

const renderContent = () => {
const renderContentDom = useMemo(() => {
const spinProps = genLoading(loading);
const dom = spinProps.spinning ? <PageLoading {...spinProps} /> : content;
if (props.waterMarkProps || value.waterMarkProps) {
return <WaterMark {...(props.waterMarkProps || value.waterMarkProps)}>{dom}</WaterMark>;
}
return dom;
};
}, [content, loading, props.waterMarkProps, value.waterMarkProps]);

return (
<div style={style} className={containerClassName}>
{fixedHeader && pageHeaderDom ? (
Expand All @@ -311,7 +318,7 @@ const PageContainer: React.FC<PageContainerProps> = (props) => {
) : (
pageHeaderDom
)}
<GridContent>{renderContent()}</GridContent>
{renderContentDom && <GridContent>{renderContentDom}</GridContent>}
{footer && <FooterToolbar prefixCls={prefixCls}>{footer}</FooterToolbar>}
</div>
);
Expand Down
Loading