mirror of
https://github.com/ant-design/ant-design.git
synced 2025-06-07 17:44:35 +08:00
feat: Typography.Text Pass event to onCopy. (#34655)
This commit is contained in:
parent
2f65904de2
commit
80377f2243
@ -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, []);
|
||||
|
@ -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.';
|
||||
|
@ -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],
|
||||
}
|
||||
|
@ -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],
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user