From 5e409fdb10df0274a2bef1d9aec074ca625cc776 Mon Sep 17 00:00:00 2001 From: tanjinzhou <415800467@qq.com> Date: Tue, 26 Nov 2019 15:59:29 +0800 Subject: [PATCH] fix: select input width and placeholder Incorrect When typing Chinese #1458 --- components/_util/antInputDirective.js | 3 +++ components/vc-select/Select.jsx | 17 +++++++++++++---- components/vc-tree-select/src/SearchInput.jsx | 19 ++++++++++++++++--- 3 files changed, 32 insertions(+), 7 deletions(-) diff --git a/components/_util/antInputDirective.js b/components/_util/antInputDirective.js index abbb4d7fe..aad61bb32 100644 --- a/components/_util/antInputDirective.js +++ b/components/_util/antInputDirective.js @@ -17,12 +17,15 @@ function makeMap(str, expectsLowerCase) { const isTextInputType = makeMap('text,number,password,search,email,tel,url'); function onCompositionStart(e) { + e.target.originPlaceholder = e.target.placeholder; + e.target.placeholder = ''; e.target.composing = true; } function onCompositionEnd(e) { // prevent triggering an input event for no reason if (!e.target.composing) return; + e.target.placeholder = e.target.originPlaceholder; e.target.composing = false; trigger(e.target, 'input'); } diff --git a/components/vc-select/Select.jsx b/components/vc-select/Select.jsx index faf59cfd9..0e7695ac5 100644 --- a/components/vc-select/Select.jsx +++ b/components/vc-select/Select.jsx @@ -147,6 +147,7 @@ const Select = { }; return { ...state, + _mirrorInputValue: state._inputValue, // https://github.com/vueComponent/ant-design-vue/issues/1458 ...this.getDerivedStateFromProps(props, state), }; }, @@ -167,6 +168,9 @@ const Select = { __propsSymbol__() { Object.assign(this.$data, this.getDerivedStateFromProps(getOptionProps(this), this.$data)); }, + '$data._inputValue': function(val) { + this.$data._mirrorInputValue = val; + }, }, updated() { this.$nextTick(() => { @@ -305,7 +309,12 @@ const Select = { onInputChange(e) { const { value: val, composing } = e.target; const { _inputValue = '' } = this.$data; - if (composing || _inputValue === val) return; + if (composing || _inputValue === val) { + this.setState({ + _mirrorInputValue: val, + }); + return; + } const { tokenSeparators } = this.$props; if ( isMultipleOrTags(this.$props) && @@ -606,7 +615,7 @@ const Select = { getPlaceholderElement() { const { $props: props, $data: state } = this; let hidden = false; - if (state._inputValue) { + if (state._mirrorInputValue) { hidden = true; } const value = state._value; @@ -733,7 +742,7 @@ const Select = { }, _getInputElement() { const props = this.$props; - const { _inputValue: inputValue } = this.$data; + const { _inputValue: inputValue, _mirrorInputValue } = this.$data; const attrs = getAttrs(this); const defaultInput = ( - {inputValue}  + {_mirrorInputValue}  ); diff --git a/components/vc-tree-select/src/SearchInput.jsx b/components/vc-tree-select/src/SearchInput.jsx index ba8b81c38..d1106112c 100644 --- a/components/vc-tree-select/src/SearchInput.jsx +++ b/components/vc-tree-select/src/SearchInput.jsx @@ -22,7 +22,16 @@ const SearchInput = { inject: { vcTreeSelect: { default: () => ({}) }, }, - + data() { + return { + mirrorSearchValue: this.searchValue, + }; + }, + watch: { + searchValue(val) { + this.mirrorSearchValue = val; + }, + }, created() { this.inputRef = createRef(); this.mirrorInputRef = createRef(); @@ -89,7 +98,10 @@ const SearchInput = { handleInputChange(e) { const { value, composing } = e.target; const { searchValue = '' } = this; - if (composing || searchValue === value) return; + if (composing || searchValue === value) { + this.mirrorSearchValue = value; + return; + } this.vcTreeSelect.onSearchInputChange(e); }, }, @@ -99,6 +111,7 @@ const SearchInput = { const { vcTreeSelect: { onSearchInputKeyDown }, handleInputChange, + mirrorSearchValue, } = this; return ( @@ -136,7 +149,7 @@ const SearchInput = { }} class={`${prefixCls}-search__field__mirror`} > - {searchValue}  + {mirrorSearchValue}  {renderPlaceholder ? renderPlaceholder() : null}