Browse Source

Merge pull request #27485 from ant-design/pageHeader

fix(pageHeader): if title is null,no render title view
pull/27497/head
信鑫-King 4 years ago
committed by GitHub
parent
commit
47c61cb776
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      components/page-header/__tests__/index.test.js
  2. 25
      components/page-header/index.tsx

12
components/page-header/__tests__/index.test.js

@ -50,6 +50,18 @@ describe('PageHeader', () => {
expect(wrapper.find('.ant-page-header-back')).toHaveLength(0); 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(<PageHeader breadcrumb={{ routes }}>test</PageHeader>);
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', () => { it('pageHeader should no contain back', () => {
const wrapper = mount(<PageHeader title="Page Title" backIcon={false} />); const wrapper = mount(<PageHeader title="Page Title" backIcon={false} />);
expect(wrapper.find('.ant-page-header-back')).toHaveLength(0); expect(wrapper.find('.ant-page-header-back')).toHaveLength(0);

25
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 renderTitle = (prefixCls: string, props: PageHeaderProps, direction: string = 'ltr') => {
const { title, avatar, subTitle, tags, extra, onBack } = props; const { title, avatar, subTitle, tags, extra, onBack } = props;
const headingPrefixCls = `${prefixCls}-heading`; const headingPrefixCls = `${prefixCls}-heading`;
if (title || subTitle || tags || extra) { const hasHeading = title || subTitle || tags || extra;
const backIcon = getBackIcon(props, direction); // 如果 什么都没有,直接返回一个 null
const backIconDom = renderBack(prefixCls, backIcon, onBack); if (!hasHeading) {
return ( return null;
<div className={headingPrefixCls}> }
const backIcon = getBackIcon(props, direction);
const backIconDom = renderBack(prefixCls, backIcon, onBack);
const hasTitle = backIconDom || avatar || hasHeading;
return (
<div className={headingPrefixCls}>
{hasTitle && (
<div className={`${headingPrefixCls}-left`}> <div className={`${headingPrefixCls}-left`}>
{backIconDom} {backIconDom}
{avatar && <Avatar {...avatar} />} {avatar && <Avatar {...avatar} />}
@ -95,11 +101,10 @@ const renderTitle = (prefixCls: string, props: PageHeaderProps, direction: strin
)} )}
{tags && <span className={`${headingPrefixCls}-tags`}>{tags}</span>} {tags && <span className={`${headingPrefixCls}-tags`}>{tags}</span>}
</div> </div>
{extra && <span className={`${headingPrefixCls}-extra`}>{extra}</span>} )}
</div> {extra && <span className={`${headingPrefixCls}-extra`}>{extra}</span>}
); </div>
} );
return null;
}; };
const renderFooter = (prefixCls: string, footer: React.ReactNode) => { const renderFooter = (prefixCls: string, footer: React.ReactNode) => {

Loading…
Cancel
Save