From eb82bae9af694cc8d28a30dac06f7825179cb615 Mon Sep 17 00:00:00 2001 From: tangjinzhou <415800467@qq.com> Date: Thu, 8 Feb 2018 18:56:58 +0800 Subject: [PATCH] fix --- components/vc-select/Select.vue | 106 +++++++++++++++++++++---- components/vc-select/SelectTrigger.vue | 5 +- 2 files changed, 96 insertions(+), 15 deletions(-) diff --git a/components/vc-select/Select.vue b/components/vc-select/Select.vue index 4bad27bbf..662f761c4 100644 --- a/components/vc-select/Select.vue +++ b/components/vc-select/Select.vue @@ -94,13 +94,15 @@ export default { if (sOpen === undefined) { sOpen = defaultOpen } - this.adjustOpenState() return { sValue, inputValue, sOpen, } }, + beforeMount () { + this.adjustOpenState() + }, mounted () { this.$nextTick(() => { this.autoFocus && this.focus() @@ -144,7 +146,10 @@ export default { } }) }, - + beforeUpdate () { + console.log('beforeUpdate') + this.adjustOpenState() + }, beforeDestroy () { this.clearFocusTime() this.clearBlurTime() @@ -315,19 +320,23 @@ export default { }, onArrowClick (e) { - e.stopPropagation() - if (!this.disabled) { - this.setOpenState(!this.sOpen, !this.sOpen) - } + // e.stopPropagation() + // if (!this.disabled) { + // this.setOpenState(!this.sOpen, !this.sOpen) + // } }, - onPlaceholderClick () { + onPlaceholderClick (e) { + if (this._focused) { + e.stopPropagation() + } if (this.getInputDOMNode()) { this.getInputDOMNode().focus() } }, onOuterFocus (e) { + console.log('onOuterFocus') if (this.disabled) { e.preventDefault() return @@ -386,7 +395,7 @@ export default { // why not use setState? this.inputValue = this.getInputDOMNode().value = '' } - this._emit('blur', this.getVLForOnChange(sValue)) + this.__emit('blur', this.getVLForOnChange(sValue)) this.setOpenState(false) }, 10) }, @@ -528,7 +537,18 @@ export default { } return null }, - + inputClick (e) { + if (this._focused) { + e.stopPropagation() + } + }, + inputBlur (e) { + // console.log(e.target) + this.onOuterBlur() + if (!this.disabled) { + this.setOpenState(!this.sOpen, !this.sOpen) + } + }, _getInputElement () { const props = this.$props const inputElement = props.getInputElement @@ -537,15 +557,15 @@ export default { const inputCls = classnames(getClass(inputElement), { [`${props.prefixCls}-search__field`]: true, }) + const inputEvents = getEvents(inputElement) // https://github.com/ant-design/ant-design/issues/4992#issuecomment-281542159 // Add space to the end of the inputValue as the width measurement tolerance return (
{cloneElement(inputElement, { - props: { + attrs: { value: this.inputValue, disabled: props.disabled, - }, class: inputCls, ref: 'inputRef', @@ -553,9 +573,21 @@ export default { input: this.onInputChange, keydown: chaining( this.onInputKeydown, - getEvents(inputElement).keydown || noop, + inputEvents.keydown || noop, this.$listeners.inputKeydown ), + // focus: chaining( + // this.onOuterFocus, + // inputEvents.focus || noop, + // ), + blur: chaining( + this.inputBlur, + inputEvents.blur || noop, + ), + click: chaining( + this.inputClick, + inputEvents.click || noop, + ), }, })}