mirror of
https://github.com/ant-design/ant-design.git
synced 2024-11-28 05:05:48 +08:00
fix: Typography copyable in clipboard incorrect (#34034)
Co-authored-by: chenxq <chenxq@neocrm.com>
This commit is contained in:
parent
0596e338ca
commit
58c1998e1e
@ -197,10 +197,7 @@ const Base = React.forwardRef((props: InternalBlockProps, ref: any) => {
|
||||
e?.preventDefault();
|
||||
e?.stopPropagation();
|
||||
|
||||
if (copyConfig.text === undefined) {
|
||||
copyConfig.text = String(children);
|
||||
}
|
||||
copy(copyConfig.text || '');
|
||||
copy(copyConfig.text || String(children) || '');
|
||||
|
||||
setCopied(true);
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
import React from 'react';
|
||||
import { mount } from 'enzyme';
|
||||
import { SmileOutlined, LikeOutlined } from '@ant-design/icons';
|
||||
import * as copyObj from 'copy-to-clipboard';
|
||||
|
||||
import Base from '../Base';
|
||||
|
||||
@ -206,5 +207,34 @@ describe('Typography copy', () => {
|
||||
wrapper.find('.ant-typography-copy').first().simulate('click');
|
||||
expect(onDivClick).not.toBeCalled();
|
||||
});
|
||||
|
||||
it('copy to clipboard', done => {
|
||||
const spy = jest.spyOn(copyObj, 'default');
|
||||
const originText = 'origin text.';
|
||||
const nextText = 'next text.';
|
||||
const Test = () => {
|
||||
const [dynamicText, setDynamicText] = React.useState(originText);
|
||||
React.useEffect(() => {
|
||||
setTimeout(() => {
|
||||
setDynamicText(nextText);
|
||||
}, 500);
|
||||
});
|
||||
return (
|
||||
<Base component="p" copyable>
|
||||
{dynamicText}
|
||||
</Base>
|
||||
);
|
||||
};
|
||||
const wrapper = mount(<Test />);
|
||||
const copyBtn = wrapper.find('.ant-typography-copy').first();
|
||||
copyBtn.simulate('click');
|
||||
expect(spy.mock.calls[0][0]).toEqual(originText);
|
||||
setTimeout(() => {
|
||||
spy.mockReset();
|
||||
copyBtn.simulate('click');
|
||||
expect(spy.mock.calls[0][0]).toEqual(nextText);
|
||||
done();
|
||||
}, 500);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user