🐛 fix Tag onClick triggered when close (#20355)

close #20344
This commit is contained in:
偏右 2019-12-19 22:12:37 +08:00 committed by GitHub
parent 38dab1f725
commit 6e27c62eb3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 0 deletions

View File

@ -39,6 +39,16 @@ describe('Tag', () => {
expect(wrapper.find('.ant-tag:not(.ant-tag-hidden)').length).toBe(1);
});
// https://github.com/ant-design/ant-design/issues/20344
it('should not trigger onClick when click close icon', () => {
const onClose = jest.fn();
const onClick = jest.fn();
const wrapper = mount(<Tag closable onClose={onClose} onClick={onClick} />);
wrapper.find('.anticon-close').simulate('click');
expect(onClose).toHaveBeenCalled();
expect(onClick).not.toHaveBeenCalled();
});
describe('visibility', () => {
it('can be controlled by visible with visible as initial value', () => {
const wrapper = mount(<Tag visible />);

View File

@ -100,6 +100,7 @@ class Tag extends React.Component<TagProps, TagState> {
}
handleIconClick = (e: React.MouseEvent<HTMLElement>) => {
e.stopPropagation();
this.setVisible(false, e);
};