fix: Typography copyable add stopPropagation (#33998)

* fix: Typography copyable add stopPropagation

* add test
This commit is contained in:
linxianxi 2022-02-10 16:22:31 +08:00 committed by GitHub
parent 4f8646f957
commit 19cc7d49e2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 0 deletions

View File

@ -194,6 +194,7 @@ const Base = React.forwardRef((props: InternalBlockProps, ref: any) => {
const onCopyClick = (e?: React.MouseEvent<HTMLDivElement>) => {
e?.preventDefault();
e?.stopPropagation();
if (copyConfig.text === undefined) {
copyConfig.text = String(children);

View File

@ -193,5 +193,18 @@ describe('Typography copy', () => {
tooltipLength: 0,
});
});
it('copy click event stopPropagation', () => {
const onDivClick = jest.fn();
const wrapper = mount(
<div onClick={onDivClick}>
<Base component="p" copyable>
test copy
</Base>
</div>,
);
wrapper.find('.ant-typography-copy').first().simulate('click');
expect(onDivClick).not.toBeCalled();
});
});
});