Skip to content

Commit 5e409fd

Browse files
committed
fix: select input width and placeholder Incorrect When typing Chinese #1458
1 parent 309baa1 commit 5e409fd

File tree

3 files changed

+32
-7
lines changed

3 files changed

+32
-7
lines changed

components/_util/antInputDirective.js

+3
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,15 @@ function makeMap(str, expectsLowerCase) {
1717
const isTextInputType = makeMap('text,number,password,search,email,tel,url');
1818

1919
function onCompositionStart(e) {
20+
e.target.originPlaceholder = e.target.placeholder;
21+
e.target.placeholder = '';
2022
e.target.composing = true;
2123
}
2224

2325
function onCompositionEnd(e) {
2426
// prevent triggering an input event for no reason
2527
if (!e.target.composing) return;
28+
e.target.placeholder = e.target.originPlaceholder;
2629
e.target.composing = false;
2730
trigger(e.target, 'input');
2831
}

components/vc-select/Select.jsx

+13-4
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ const Select = {
147147
};
148148
return {
149149
...state,
150+
_mirrorInputValue: state._inputValue, // https://github.com/vueComponent/ant-design-vue/issues/1458
150151
...this.getDerivedStateFromProps(props, state),
151152
};
152153
},
@@ -167,6 +168,9 @@ const Select = {
167168
__propsSymbol__() {
168169
Object.assign(this.$data, this.getDerivedStateFromProps(getOptionProps(this), this.$data));
169170
},
171+
'$data._inputValue': function(val) {
172+
this.$data._mirrorInputValue = val;
173+
},
170174
},
171175
updated() {
172176
this.$nextTick(() => {
@@ -305,7 +309,12 @@ const Select = {
305309
onInputChange(e) {
306310
const { value: val, composing } = e.target;
307311
const { _inputValue = '' } = this.$data;
308-
if (composing || _inputValue === val) return;
312+
if (composing || _inputValue === val) {
313+
this.setState({
314+
_mirrorInputValue: val,
315+
});
316+
return;
317+
}
309318
const { tokenSeparators } = this.$props;
310319
if (
311320
isMultipleOrTags(this.$props) &&
@@ -606,7 +615,7 @@ const Select = {
606615
getPlaceholderElement() {
607616
const { $props: props, $data: state } = this;
608617
let hidden = false;
609-
if (state._inputValue) {
618+
if (state._mirrorInputValue) {
610619
hidden = true;
611620
}
612621
const value = state._value;
@@ -733,7 +742,7 @@ const Select = {
733742
},
734743
_getInputElement() {
735744
const props = this.$props;
736-
const { _inputValue: inputValue } = this.$data;
745+
const { _inputValue: inputValue, _mirrorInputValue } = this.$data;
737746
const attrs = getAttrs(this);
738747
const defaultInput = (
739748
<input
@@ -802,7 +811,7 @@ const Select = {
802811
// ref='inputMirrorRef'
803812
class={`${props.prefixCls}-search__field__mirror`}
804813
>
805-
{inputValue}&nbsp;
814+
{_mirrorInputValue}&nbsp;
806815
</span>
807816
</div>
808817
);

components/vc-tree-select/src/SearchInput.jsx

+16-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,16 @@ const SearchInput = {
2222
inject: {
2323
vcTreeSelect: { default: () => ({}) },
2424
},
25-
25+
data() {
26+
return {
27+
mirrorSearchValue: this.searchValue,
28+
};
29+
},
30+
watch: {
31+
searchValue(val) {
32+
this.mirrorSearchValue = val;
33+
},
34+
},
2635
created() {
2736
this.inputRef = createRef();
2837
this.mirrorInputRef = createRef();
@@ -89,7 +98,10 @@ const SearchInput = {
8998
handleInputChange(e) {
9099
const { value, composing } = e.target;
91100
const { searchValue = '' } = this;
92-
if (composing || searchValue === value) return;
101+
if (composing || searchValue === value) {
102+
this.mirrorSearchValue = value;
103+
return;
104+
}
93105
this.vcTreeSelect.onSearchInputChange(e);
94106
},
95107
},
@@ -99,6 +111,7 @@ const SearchInput = {
99111
const {
100112
vcTreeSelect: { onSearchInputKeyDown },
101113
handleInputChange,
114+
mirrorSearchValue,
102115
} = this;
103116
return (
104117
<span class={`${prefixCls}-search__field__wrap`}>
@@ -136,7 +149,7 @@ const SearchInput = {
136149
}}
137150
class={`${prefixCls}-search__field__mirror`}
138151
>
139-
{searchValue}&nbsp;
152+
{mirrorSearchValue}&nbsp;
140153
</span>
141154
{renderPlaceholder ? renderPlaceholder() : null}
142155
</span>

0 commit comments

Comments
 (0)