Skip to content

Commit f6838d2

Browse files
authored
Revert "fix: keep onChange target mounted when value does not need cloning" (#176)
1 parent 1889137 commit f6838d2

2 files changed

Lines changed: 1 addition & 28 deletions

File tree

src/utils/commonUtils.ts

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,6 @@ function cloneEvent<
4545
return newEvent;
4646
}
4747

48-
function cloneEventWithTarget<
49-
EventType extends React.SyntheticEvent<any, any>,
50-
Element extends HTMLInputElement | HTMLTextAreaElement,
51-
>(event: EventType, target: Element): EventType {
52-
return Object.create(event, {
53-
target: { value: target },
54-
currentTarget: { value: target },
55-
});
56-
}
57-
5848
export function resolveOnChange<
5949
E extends HTMLInputElement | HTMLTextAreaElement,
6050
>(
@@ -94,11 +84,7 @@ export function resolveOnChange<
9484
// https://github.com/ant-design/ant-design/issues/45737
9585
// https://github.com/ant-design/ant-design/issues/46598
9686
if (target.type !== 'file' && targetValue !== undefined) {
97-
if (target.value !== targetValue) {
98-
event = cloneEvent(e, target, targetValue);
99-
} else {
100-
event = cloneEventWithTarget(e, target);
101-
}
87+
event = cloneEvent(e, target, targetValue);
10288
onChange(event as React.ChangeEvent<E>);
10389
return;
10490
}

tests/index.test.tsx

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -439,19 +439,6 @@ describe('Input ref', () => {
439439
expect(spySetSelectionRange).toHaveBeenCalledWith(1, 2);
440440
});
441441

442-
it('onChange target should be the mounted input when value is unchanged by formatter', () => {
443-
const onChange = jest.fn();
444-
const { container } = render(<Input onChange={onChange} />);
445-
const inputEl = container.querySelector('input')!;
446-
447-
fireEvent.change(inputEl, { target: { value: 'test' } });
448-
449-
const event = onChange.mock.calls[0][0];
450-
expect(event.target).toBe(inputEl);
451-
expect(event.currentTarget).toBe(inputEl);
452-
expect(document.contains(event.target)).toBe(true);
453-
});
454-
455442
it('email type not support selection', () => {
456443
const onChange = jest.fn();
457444
const { container } = render(<Input type="email" onChange={onChange} />);

0 commit comments

Comments
 (0)