mirror of
https://github.com/ant-design/ant-design.git
synced 2024-11-24 19:19:57 +08:00
fix: Exception in enter key callback on editable or copyable Paragraph (#33976)
* fix: Exception on enter key callback * Move spyOn position
This commit is contained in:
parent
29d340724e
commit
745ebf2d84
@ -168,8 +168,8 @@ const Base = React.forwardRef((props: InternalBlockProps, ref: any) => {
|
||||
}
|
||||
}, [editing]);
|
||||
|
||||
const onEditClick = (e: React.MouseEvent<HTMLDivElement>) => {
|
||||
e.preventDefault();
|
||||
const onEditClick = (e?: React.MouseEvent<HTMLDivElement>) => {
|
||||
e?.preventDefault();
|
||||
triggerEdit(true);
|
||||
};
|
||||
|
||||
@ -192,8 +192,8 @@ const Base = React.forwardRef((props: InternalBlockProps, ref: any) => {
|
||||
clearTimeout(copyIdRef.current!);
|
||||
};
|
||||
|
||||
const onCopyClick = (e: React.MouseEvent<HTMLDivElement>) => {
|
||||
e.preventDefault();
|
||||
const onCopyClick = (e?: React.MouseEvent<HTMLDivElement>) => {
|
||||
e?.preventDefault();
|
||||
|
||||
if (copyConfig.text === undefined) {
|
||||
copyConfig.text = String(children);
|
||||
|
32
components/typography/__tests__/enter-key-callback.test.tsx
Normal file
32
components/typography/__tests__/enter-key-callback.test.tsx
Normal file
@ -0,0 +1,32 @@
|
||||
import React from 'react';
|
||||
import { mount } from 'enzyme';
|
||||
import KeyCode from 'rc-util/lib/KeyCode';
|
||||
import Paragraph from '../Paragraph';
|
||||
|
||||
test('Callback on enter key is triggered', () => {
|
||||
const onEditStart = jest.fn();
|
||||
const onCopy = jest.fn();
|
||||
|
||||
const wrapper = mount(
|
||||
<Paragraph
|
||||
copyable={{
|
||||
onCopy,
|
||||
}}
|
||||
editable={{
|
||||
onStart: onEditStart,
|
||||
}}
|
||||
>
|
||||
test
|
||||
</Paragraph>,
|
||||
);
|
||||
const timer: any = 9527;
|
||||
jest.spyOn(window, 'setTimeout').mockReturnValue(timer);
|
||||
jest.spyOn(window, 'clearTimeout');
|
||||
// must copy first, because editing button will hide copy button
|
||||
wrapper.find('.ant-typography-copy').at(0).simulate('keyup', { keyCode: KeyCode.ENTER });
|
||||
wrapper.find('.anticon-edit').at(0).simulate('keyup', { keyCode: KeyCode.ENTER });
|
||||
|
||||
expect(onEditStart.mock.calls.length).toBe(1);
|
||||
expect(onCopy.mock.calls.length).toBe(1);
|
||||
jest.restoreAllMocks();
|
||||
});
|
Loading…
Reference in New Issue
Block a user