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..7c754562eb 100644 --- a/components/page-header/index.tsx +++ b/components/page-header/index.tsx @@ -69,11 +69,17 @@ 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); - return ( -
+ 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 || hasHeading; + return ( +
+ {hasTitle && (
{backIconDom} {avatar && } @@ -95,11 +101,10 @@ const renderTitle = (prefixCls: string, props: PageHeaderProps, direction: strin )} {tags && {tags}}
- {extra && {extra}} -
- ); - } - return null; + )} + {extra && {extra}} +
+ ); }; const renderFooter = (prefixCls: string, footer: React.ReactNode) => {