2019-01-12 11:33:27 +08:00
|
|
|
function onCompositionStart(e) {
|
|
|
|
e.target.composing = true;
|
2018-07-26 13:25:02 +08:00
|
|
|
}
|
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
function onCompositionEnd(e) {
|
2018-07-26 13:25:02 +08:00
|
|
|
// prevent triggering an input event for no reason
|
2019-01-12 11:33:27 +08:00
|
|
|
if (!e.target.composing) return;
|
|
|
|
e.target.composing = false;
|
|
|
|
trigger(e.target, 'input');
|
2018-07-26 13:25:02 +08:00
|
|
|
}
|
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
function trigger(el, type) {
|
|
|
|
const e = document.createEvent('HTMLEvents');
|
|
|
|
e.initEvent(type, true, true);
|
|
|
|
el.dispatchEvent(e);
|
2018-07-26 13:25:02 +08:00
|
|
|
}
|
|
|
|
|
2020-09-21 18:45:27 +08:00
|
|
|
export function addEventListener(el, event, handler, options) {
|
|
|
|
el.addEventListener(event, handler, options);
|
2018-07-26 13:25:02 +08:00
|
|
|
}
|
2020-09-21 18:45:27 +08:00
|
|
|
const antInput = {
|
|
|
|
created(el, binding) {
|
|
|
|
if (!binding.modifiers || !binding.modifiers.lazy) {
|
|
|
|
addEventListener(el, 'compositionstart', onCompositionStart);
|
|
|
|
addEventListener(el, 'compositionend', onCompositionEnd);
|
|
|
|
// Safari < 10.2 & UIWebView doesn't fire compositionend when
|
|
|
|
// switching focus before confirming composition choice
|
|
|
|
// this also fixes the issue where some browsers e.g. iOS Chrome
|
|
|
|
// fires "change" instead of "input" on autocomplete.
|
|
|
|
addEventListener(el, 'change', onCompositionEnd);
|
2020-07-03 22:53:50 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
};
|
2018-12-13 22:47:23 +08:00
|
|
|
|
2020-09-21 18:45:27 +08:00
|
|
|
export default antInput;
|