From ef5e6603c2702487ddd5d817ff7b258fd03170aa Mon Sep 17 00:00:00 2001 From: chenshuai2144 Date: Sun, 1 Nov 2020 22:47:10 +0800 Subject: [PATCH 1/3] fix(pageHeader): if title is null,no render title view --- .../page-header/__tests__/index.test.js | 12 +++++ components/page-header/index.tsx | 49 ++++++++++--------- 2 files changed, 39 insertions(+), 22 deletions(-) diff --git a/components/page-header/__tests__/index.test.js b/components/page-header/__tests__/index.test.js index 8e444e1ad4..85c1e69477 100644 --- a/components/page-header/__tests__/index.test.js +++ b/components/page-header/__tests__/index.test.js @@ -50,6 +50,18 @@ describe('PageHeader', () => { expect(wrapper.find('.ant-page-header-back')).toHaveLength(0); }); + it('pageHeader do not has title', () => { + const routes = [ + { + path: 'index', + breadcrumbName: 'First-level Menu', + }, + ]; + const wrapper = mount(test); + expect(wrapper.find('.ant-page-header-heading-lef').exists()).toBeFalsy(); + expect(wrapper.find('.ant-page-header-heading').exists()).toBeFalsy(); + }); + it('pageHeader should no contain back', () => { const wrapper = mount(); expect(wrapper.find('.ant-page-header-back')).toHaveLength(0); diff --git a/components/page-header/index.tsx b/components/page-header/index.tsx index ce207b227e..c2ee101eaf 100644 --- a/components/page-header/index.tsx +++ b/components/page-header/index.tsx @@ -72,31 +72,36 @@ const renderTitle = (prefixCls: string, props: PageHeaderProps, direction: strin if (title || subTitle || tags || extra) { const backIcon = getBackIcon(props, direction); const backIconDom = renderBack(prefixCls, backIcon, onBack); + const hasTitle = backIconDom || avatar || title || subTitle || tags || extra; return ( -
-
- {backIconDom} - {avatar && } - {title && ( - - {title} - + hasTitle && ( +
+ {hasTitle && ( +
+ {backIconDom} + {avatar && } + {title && ( + + {title} + + )} + {subTitle && ( + + {subTitle} + + )} + {tags && {tags}} +
)} - {subTitle && ( - - {subTitle} - - )} - {tags && {tags}} + {extra && {extra}}
- {extra && {extra}} -
+ ) ); } return null; From 04658fa0a48f6cfa3666b19c8f9e396730dd9264 Mon Sep 17 00:00:00 2001 From: chenshuai2144 Date: Mon, 2 Nov 2020 12:12:46 +0800 Subject: [PATCH 2/3] fix ci warning --- components/page-header/index.tsx | 69 ++++++++++++++++---------------- 1 file changed, 34 insertions(+), 35 deletions(-) diff --git a/components/page-header/index.tsx b/components/page-header/index.tsx index c2ee101eaf..51ad3c8e7b 100644 --- a/components/page-header/index.tsx +++ b/components/page-header/index.tsx @@ -69,42 +69,41 @@ const getBackIcon = (props: PageHeaderProps, direction: string = 'ltr') => { const renderTitle = (prefixCls: string, props: PageHeaderProps, direction: string = 'ltr') => { const { title, avatar, subTitle, tags, extra, onBack } = props; const headingPrefixCls = `${prefixCls}-heading`; - if (title || subTitle || tags || extra) { - const backIcon = getBackIcon(props, direction); - const backIconDom = renderBack(prefixCls, backIcon, onBack); - const hasTitle = backIconDom || avatar || title || subTitle || tags || extra; - return ( - hasTitle && ( -
- {hasTitle && ( -
- {backIconDom} - {avatar && } - {title && ( - - {title} - - )} - {subTitle && ( - - {subTitle} - - )} - {tags && {tags}} -
- )} - {extra && {extra}} -
- ) - ); + // 如果 什么都没有,直接返回一个 空 + if (!title && !subTitle && !tags && !extra) { + return null; } - return null; + const backIcon = getBackIcon(props, direction); + const backIconDom = renderBack(prefixCls, backIcon, onBack); + const hasTitle = backIconDom || avatar || title || subTitle || tags || extra; + return ( +
+ {hasTitle && ( +
+ {backIconDom} + {avatar && } + {title && ( + + {title} + + )} + {subTitle && ( + + {subTitle} + + )} + {tags && {tags}} +
+ )} + {extra && {extra}} +
+ ); }; const renderFooter = (prefixCls: string, footer: React.ReactNode) => { From d6c11fa9012e96eae2bdaefb049c462684cb740f Mon Sep 17 00:00:00 2001 From: chenshuai2144 Date: Mon, 2 Nov 2020 13:43:03 +0800 Subject: [PATCH 3/3] less code --- components/page-header/index.tsx | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/components/page-header/index.tsx b/components/page-header/index.tsx index 51ad3c8e7b..7c754562eb 100644 --- a/components/page-header/index.tsx +++ b/components/page-header/index.tsx @@ -69,13 +69,14 @@ const getBackIcon = (props: PageHeaderProps, direction: string = 'ltr') => { const renderTitle = (prefixCls: string, props: PageHeaderProps, direction: string = 'ltr') => { const { title, avatar, subTitle, tags, extra, onBack } = props; const headingPrefixCls = `${prefixCls}-heading`; - // 如果 什么都没有,直接返回一个 空 - if (!title && !subTitle && !tags && !extra) { + const hasHeading = title || subTitle || tags || extra; + // 如果 什么都没有,直接返回一个 null + if (!hasHeading) { return null; } const backIcon = getBackIcon(props, direction); const backIconDom = renderBack(prefixCls, backIcon, onBack); - const hasTitle = backIconDom || avatar || title || subTitle || tags || extra; + const hasTitle = backIconDom || avatar || hasHeading; return (
{hasTitle && (