MCPcopy Index your code
hub / github.com/react-component/input / cloneEvent

Function cloneEvent

src/utils/commonUtils.ts:13–46  ·  view source on GitHub ↗
(event: EventType, target: Element, value: any)

Source from the content-addressed store, hash-verified

11
12// TODO: It's better to use `Proxy` replace the `element.value`. But we still need support IE11.
13function cloneEvent<
14 EventType extends React.SyntheticEvent<any, any>,
15 Element extends HTMLInputElement | HTMLTextAreaElement,
16>(event: EventType, target: Element, value: any): EventType {
17 // A bug report filed on WebKit's Bugzilla tracker, dating back to 2009, specifically addresses the issue of cloneNode() not copying files of <input type="file"> elements.
18 // As of the last update, this bug was still marked as "NEW," indicating that it might not have been resolved yet​​.
19 // https://bugs.webkit.org/show_bug.cgi?id=28123
20 const currentTarget = target.cloneNode(true) as Element;
21
22 // click clear icon
23 const newEvent = Object.create(event, {
24 target: { value: currentTarget },
25 currentTarget: { value: currentTarget },
26 });
27
28 // Fill data
29 currentTarget.value = value;
30
31 // Fill selection. Some type like `email` not support selection
32 // https://github.com/ant-design/ant-design/issues/47833
33 if (
34 typeof target.selectionStart === 'number' &&
35 typeof target.selectionEnd === 'number'
36 ) {
37 currentTarget.selectionStart = target.selectionStart;
38 currentTarget.selectionEnd = target.selectionEnd;
39 }
40
41 currentTarget.setSelectionRange = (...args) => {
42 target.setSelectionRange(...args);
43 };
44
45 return newEvent;
46}
47
48export function resolveOnChange<
49 E extends HTMLInputElement | HTMLTextAreaElement,

Callers 1

resolveOnChangeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…