2020-10-02 07:44:10 +00:00
|
|
|
function onCompositionStart(e) {
|
|
|
|
e.target.composing = true;
|
2018-07-26 05:25:02 +00:00
|
|
|
}
|
|
|
|
|
2020-10-02 07:44:10 +00:00
|
|
|
function onCompositionEnd(e) {
|
|
|
|
// prevent triggering an input event for no reason
|
|
|
|
if (!e.target.composing) return;
|
|
|
|
e.target.composing = false;
|
|
|
|
trigger(e.target, 'input');
|
2018-07-26 05:25:02 +00:00
|
|
|
}
|
|
|
|
|
2020-10-02 07:44:10 +00:00
|
|
|
function trigger(el, type) {
|
2019-01-12 03:33:27 +00:00
|
|
|
const e = document.createEvent('HTMLEvents');
|
|
|
|
e.initEvent(type, true, true);
|
|
|
|
el.dispatchEvent(e);
|
2018-07-26 05:25:02 +00:00
|
|
|
}
|
|
|
|
|
2020-10-02 07:44:10 +00:00
|
|
|
export function addEventListener(el, event, handler, options) {
|
2020-09-21 10:45:27 +00:00
|
|
|
el.addEventListener(event, handler, options);
|
2018-07-26 05:25:02 +00:00
|
|
|
}
|
2020-09-21 10:45:27 +00:00
|
|
|
const antInput = {
|
2020-10-02 07:44:10 +00:00
|
|
|
created(el, binding) {
|
2020-09-21 10:45:27 +00:00
|
|
|
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 14:53:50 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
};
|
2018-12-13 14:47:23 +00:00
|
|
|
|
2020-09-21 10:45:27 +00:00
|
|
|
export default antInput;
|