Skip to content

Commit 7719c65

Browse files
committed
fix: input not trigger change compositionStart
1 parent 7f7511b commit 7719c65

File tree

4 files changed

+18
-54
lines changed

4 files changed

+18
-54
lines changed

antdv-demo

components/_util/antInputDirective.js

Lines changed: 13 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,3 @@
1-
/**
2-
* Not type checking this file because flow doesn't like attaching
3-
* properties to Elements.
4-
*/
5-
6-
export const inBrowser = typeof window !== 'undefined';
7-
export const UA = inBrowser && window.navigator.userAgent.toLowerCase();
8-
export const isIE9 = UA && UA.indexOf('msie 9.0') > 0;
9-
function makeMap(str, expectsLowerCase) {
10-
const map = Object.create(null);
11-
const list = str.split(',');
12-
for (let i = 0; i < list.length; i++) {
13-
map[list[i]] = true;
14-
}
15-
return expectsLowerCase ? val => map[val.toLowerCase()] : val => map[val];
16-
}
17-
const isTextInputType = makeMap('text,number,password,search,email,tel,url');
18-
191
function onCompositionStart(e) {
202
e.target.composing = true;
213
}
@@ -33,40 +15,21 @@ function trigger(el, type) {
3315
el.dispatchEvent(e);
3416
}
3517

36-
/* istanbul ignore if */
37-
if (isIE9) {
38-
// http://www.matts411.com/post/internet-explorer-9-oninput/
39-
document.addEventListener('selectionchange', () => {
40-
const el = document.activeElement;
41-
if (el && el.vmodel) {
42-
trigger(el, 'input');
43-
}
44-
});
18+
export function addEventListener(el, event, handler, options) {
19+
el.addEventListener(event, handler, options);
4520
}
46-
47-
export const antInput = {
48-
mounted(el, binding, vnode) {
49-
if (vnode.type === 'textarea' || isTextInputType(el.type)) {
50-
if (!binding.modifiers || !binding.modifiers.lazy) {
51-
el.addEventListener('compositionstart', onCompositionStart);
52-
el.addEventListener('compositionend', onCompositionEnd);
53-
// Safari < 10.2 & UIWebView doesn't fire compositionend when
54-
// switching focus before confirming composition choice
55-
// this also fixes the issue where some browsers e.g. iOS Chrome
56-
// fires "change" instead of "input" on autocomplete.
57-
el.addEventListener('change', onCompositionEnd);
58-
/* istanbul ignore if */
59-
if (isIE9) {
60-
el.vmodel = true;
61-
}
62-
}
21+
const antInput = {
22+
created(el, binding) {
23+
if (!binding.modifiers || !binding.modifiers.lazy) {
24+
addEventListener(el, 'compositionstart', onCompositionStart);
25+
addEventListener(el, 'compositionend', onCompositionEnd);
26+
// Safari < 10.2 & UIWebView doesn't fire compositionend when
27+
// switching focus before confirming composition choice
28+
// this also fixes the issue where some browsers e.g. iOS Chrome
29+
// fires "change" instead of "input" on autocomplete.
30+
addEventListener(el, 'change', onCompositionEnd);
6331
}
6432
},
6533
};
6634

67-
export default {
68-
install: app => {
69-
antInput(app);
70-
app.directive('ant-input', antInput);
71-
},
72-
};
35+
export default antInput;

components/input/Input.jsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { inject } from 'vue';
1+
import { inject, withDirectives } from 'vue';
2+
import antInputDirective from '../_util/antInputDirective';
23
import classNames from '../_util/classNames';
34
import omit from 'omit.js';
45
import inputProps from './inputProps';
@@ -164,7 +165,7 @@ export default {
164165
if (!inputProps.autofocus) {
165166
delete inputProps.autofocus;
166167
}
167-
return <input {...inputProps} />;
168+
return withDirectives(<input {...inputProps} />, [[antInputDirective]]);
168169
},
169170
clearPasswordValueAttribute() {
170171
// https://github.com/ant-design/ant-design/issues/20541

examples/App.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
</div>
55
</template>
66
<script>
7-
import demo from '../antdv-demo/docs/form/demo';
7+
import demo from '../antdv-demo/docs/input/demo/basic.md';
88
export default {
99
components: {
1010
demo,

0 commit comments

Comments
 (0)