1
This commit is contained in:
+71
@@ -0,0 +1,71 @@
|
||||
export function hasAddon(props) {
|
||||
return !!(props.addonBefore || props.addonAfter);
|
||||
}
|
||||
export function hasPrefixSuffix(props) {
|
||||
return !!(props.prefix || props.suffix || props.allowClear);
|
||||
}
|
||||
|
||||
// TODO: It's better to use `Proxy` replace the `element.value`. But we still need support IE11.
|
||||
function cloneEvent(event, target, value) {
|
||||
// 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.
|
||||
// As of the last update, this bug was still marked as "NEW," indicating that it might not have been resolved yet.
|
||||
// https://bugs.webkit.org/show_bug.cgi?id=28123
|
||||
const currentTarget = target.cloneNode(true);
|
||||
|
||||
// click clear icon
|
||||
const newEvent = Object.create(event, {
|
||||
target: {
|
||||
value: currentTarget
|
||||
},
|
||||
currentTarget: {
|
||||
value: currentTarget
|
||||
}
|
||||
});
|
||||
|
||||
// Fill data
|
||||
currentTarget.value = value;
|
||||
|
||||
// Fill selection. Some type like `email` not support selection
|
||||
// https://github.com/ant-design/ant-design/issues/47833
|
||||
if (typeof target.selectionStart === 'number' && typeof target.selectionEnd === 'number') {
|
||||
currentTarget.selectionStart = target.selectionStart;
|
||||
currentTarget.selectionEnd = target.selectionEnd;
|
||||
}
|
||||
currentTarget.setSelectionRange = (...args) => {
|
||||
target.setSelectionRange(...args);
|
||||
};
|
||||
return newEvent;
|
||||
}
|
||||
export function resolveOnChange(target, e, onChange, targetValue) {
|
||||
if (!onChange) {
|
||||
return;
|
||||
}
|
||||
let event = e;
|
||||
if (e.type === 'click') {
|
||||
// Clone a new target for event.
|
||||
// Avoid the following usage, the setQuery method gets the original value.
|
||||
//
|
||||
// const [query, setQuery] = React.useState('');
|
||||
// <Input
|
||||
// allowClear
|
||||
// value={query}
|
||||
// onChange={(e)=> {
|
||||
// setQuery((prevStatus) => e.target.value);
|
||||
// }}
|
||||
// />
|
||||
|
||||
event = cloneEvent(e, target, '');
|
||||
onChange(event);
|
||||
return;
|
||||
}
|
||||
|
||||
// Trigger by composition event, this means we need force change the input value
|
||||
// https://github.com/ant-design/ant-design/issues/45737
|
||||
// https://github.com/ant-design/ant-design/issues/46598
|
||||
if (target.type !== 'file' && targetValue !== undefined) {
|
||||
event = cloneEvent(e, target, targetValue);
|
||||
onChange(event);
|
||||
return;
|
||||
}
|
||||
onChange(event);
|
||||
}
|
||||
Reference in New Issue
Block a user