feat: Typography.Text Pass event to onCopy. (#34655)

This commit is contained in:
youngz 2022-03-22 16:52:44 +08:00 committed by GitHub
parent 2f65904de2
commit 80377f2243
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 16 additions and 4 deletions

View File

@ -27,7 +27,7 @@ export type BaseType = 'secondary' | 'success' | 'warning' | 'danger';
interface CopyConfig {
text?: string;
onCopy?: () => void;
onCopy?: (event?: React.MouseEvent<HTMLDivElement>) => void;
icon?: React.ReactNode;
tooltips?: boolean | React.ReactNode;
}
@ -207,7 +207,7 @@ const Base = React.forwardRef((props: InternalBlockProps, ref: any) => {
setCopied(false);
}, 3000);
copyConfig.onCopy?.();
copyConfig.onCopy?.(e);
};
React.useEffect(() => cleanCopyId, []);

View File

@ -208,6 +208,18 @@ describe('Typography copy', () => {
expect(onDivClick).not.toBeCalled();
});
it('the first parameter of onCopy is the click event', () => {
function onCopy(e: React.MouseEvent<HTMLDivElement>) {
expect(e).not.toBeUndefined();
}
const wrapper = mount(
<Base component="p" copyable={{ onCopy }}>
test copy
</Base>,
);
wrapper.find('.ant-typography-copy').first().simulate('click');
});
it('copy to clipboard', done => {
const spy = jest.spyOn(copyObj, 'default');
const originText = 'origin text.';

View File

@ -71,7 +71,7 @@ Basic text writing, including headings, body text, lists, and more.
{
text: string,
onCopy: function,
onCopy: function(event),
icon: ReactNode,
tooltips: false | [ReactNode, ReactNode],
}

View File

@ -72,7 +72,7 @@ cover: https://gw.alipayobjects.com/zos/alicdn/GOM1KQ24O/Typography.svg
{
text: string,
onCopy: function,
onCopy: function(event),
icon: ReactNode,
tooltips: false | [ReactNode, ReactNode],
}