From 19cc7d49e2f1a27eb1483355735eb8ff1f165f17 Mon Sep 17 00:00:00 2001 From: linxianxi <47104575+linxianxi@users.noreply.github.com> Date: Thu, 10 Feb 2022 16:22:31 +0800 Subject: [PATCH] fix: Typography copyable add stopPropagation (#33998) * fix: Typography copyable add stopPropagation * add test --- components/typography/Base/index.tsx | 1 + components/typography/__tests__/copy.test.tsx | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/components/typography/Base/index.tsx b/components/typography/Base/index.tsx index 70d8c99575..706fad6c8d 100644 --- a/components/typography/Base/index.tsx +++ b/components/typography/Base/index.tsx @@ -194,6 +194,7 @@ const Base = React.forwardRef((props: InternalBlockProps, ref: any) => { const onCopyClick = (e?: React.MouseEvent) => { e?.preventDefault(); + e?.stopPropagation(); if (copyConfig.text === undefined) { copyConfig.text = String(children); diff --git a/components/typography/__tests__/copy.test.tsx b/components/typography/__tests__/copy.test.tsx index 7dc502cd1e..d831d5c7de 100644 --- a/components/typography/__tests__/copy.test.tsx +++ b/components/typography/__tests__/copy.test.tsx @@ -193,5 +193,18 @@ describe('Typography copy', () => { tooltipLength: 0, }); }); + + it('copy click event stopPropagation', () => { + const onDivClick = jest.fn(); + const wrapper = mount( +
+ + test copy + +
, + ); + wrapper.find('.ant-typography-copy').first().simulate('click'); + expect(onDivClick).not.toBeCalled(); + }); }); });