change onclick dom

This commit is contained in:
陈帅 2019-04-25 12:18:01 +08:00
parent 1ece80f6bc
commit 6055905ae4
3 changed files with 14 additions and 13 deletions

View File

@ -6,7 +6,7 @@ import * as React from 'react';
import KeyCode from 'rc-util/lib/KeyCode';
interface TransButtonProps extends React.HTMLAttributes<HTMLDivElement> {
onClick?: () => void;
onClick?: (e?: React.MouseEvent<HTMLDivElement>) => void;
}
const inlineStyle: React.CSSProperties = {

View File

@ -21,7 +21,7 @@ describe('PageHeader', () => {
const wrapper = mount(<PageHeader title="Page Title" breadcrumb={{ routes }} />);
expect(wrapper.find('.ant-page-header-back-icon')).toHaveLength(0);
});
it('pageHeader should no contain back it back', () => {
it('pageHeader should no contain back', () => {
const wrapper = mount(<PageHeader title="Page Title" backIcon={false} />);
expect(wrapper.find('.ant-page-header-back-icon')).toHaveLength(0);
});
@ -35,7 +35,7 @@ describe('PageHeader', () => {
it('pageHeader onBack transfer', () => {
const callback = jest.fn(() => true);
const wrapper = mount(<PageHeader title="Page Title" onBack={callback} />);
wrapper.find('.ant-page-header-back-icon').simulate('click');
wrapper.find('div.ant-page-header-back-icon-button').simulate('click');
expect(callback).toHaveBeenCalled();
});

View File

@ -19,7 +19,7 @@ export interface PageHeaderProps {
tags?: React.ReactElement<Tag> | React.ReactElement<Tag>[];
footer?: React.ReactNode;
extra?: React.ReactNode;
onBack?: (e: React.MouseEvent<HTMLElement>) => void;
onBack?: (e: React.MouseEvent<HTMLDivElement>) => void;
className?: string;
}
@ -34,15 +34,16 @@ const renderBack = (
return (
<LocaleReceiver componentName="PageHeader">
{({ back }: { back: string }) => (
<div
className={`${prefixCls}-back-icon`}
onClick={e => {
if (onBack) {
onBack(e);
}
}}
>
<TransButton className={`${prefixCls}-back-icon-button`} aria-label={back}>
<div className={`${prefixCls}-back-icon`}>
<TransButton
onClick={(e: React.MouseEvent<HTMLDivElement>) => {
if (onBack) {
onBack(e);
}
}}
className={`${prefixCls}-back-icon-button`}
aria-label={back}
>
{backIcon}
</TransButton>
<Divider type="vertical" />