pull/9/head
tjz 7 years ago
parent 59c194853b
commit 69166f5fb5

@ -99,7 +99,7 @@ export default {
let inputValue = '' let inputValue = ''
if (combobox) { if (combobox) {
inputValue = sValue.length inputValue = sValue.length
? this.getLabelFromProps(sValue[0].key) ? this.labelMap.get((sValue[0].key))
: '' : ''
} }
let sOpen = open let sOpen = open
@ -116,9 +116,7 @@ export default {
sOpen, sOpen,
} }
}, },
beforeMount () {
// this.adjustOpenState()
},
mounted () { mounted () {
this.$nextTick(() => { this.$nextTick(() => {
this.autoFocus && this.focus() this.autoFocus && this.focus()
@ -141,14 +139,16 @@ export default {
this.sValue = sValue this.sValue = sValue
if (this.combobox) { if (this.combobox) {
this.setState({ this.setState({
inputValue: sValue.length inputValue: sValue.length ? this.labelMap.get((sValue[0].key)) : '',
? this.getLabelFromProps(sValue[0].key)
: '',
}) })
} }
}, },
combobox () { combobox (val) {
this.updateState() if (val) {
this.setState({
inputValue: this.sValue.length ? this.labelMap.get((this.sValue[0].key)) : '',
})
}
}, },
}, },
updated () { updated () {
@ -189,22 +189,6 @@ export default {
} }
}) })
}, },
updateState () {
const { combobox, $slots } = this
let value = toArray(this.value)
value = this.addLabelToValue(value)
value = this.addTitleToValue($slots.default, value)
this.setState({
sValue: value,
})
if (combobox) {
this.setState({
inputValue: value.length
? this.getLabelFromProps(value[0].key)
: '',
})
}
},
onInputChange (event) { onInputChange (event) {
const { tokenSeparators } = this const { tokenSeparators } = this
const val = event.target.value const val = event.target.value
@ -459,20 +443,6 @@ export default {
} else { } else {
event.stopPropagation() event.stopPropagation()
} }
// const { inputValue, sValue, disabled } = this
// if (disabled) {
// return
// }
// event.stopPropagation()
// if (inputValue || sValue.length) {
// if (sValue.length) {
// this.fireChange([])
// }
// this.setOpenState(false, true)
// if (inputValue) {
// this.setInputValue('')
// }
// }
}, },
onChoiceAnimationLeave () { onChoiceAnimationLeave () {
@ -588,7 +558,7 @@ export default {
if (!this.labelInValue) { if (!this.labelInValue) {
vls = vls.map(v => v.key) vls = vls.map(v => v.key)
} else { } else {
vls = vls.map(vl => ({ key: vl.key, label: this.labelMap.get('label') })) vls = vls.map(vl => ({ key: vl.key, label: this.labelMap.get(vl.key) }))
} }
return isMultipleOrTags(this.$props) ? vls : vls[0] return isMultipleOrTags(this.$props) ? vls : vls[0]
} }
@ -926,42 +896,42 @@ export default {
} }
}, },
addLabelToValue (value_) { // addLabelToValue (value_) {
let value = value_ // let value = value_
if (this.labelInValue) { // if (this.labelInValue) {
value.forEach(v => { // value.forEach(v => {
v.label = v.label || this.getLabelFromProps(v.key) // v.label = v.label || this.getLabelFromProps(v.key)
}) // })
} else { // } else {
value = value.map(v => { // value = value.map(v => {
return { // return {
key: v, // key: v,
label: this.getLabelFromProps(v), // label: this.getLabelFromProps(v),
} // }
}) // })
} // }
return value // return value
}, // },
addTitleToValue (children = [], values) { // addTitleToValue (children = [], values) {
let nextValues = values // let nextValues = values
const keys = values.map(v => v.key) // const keys = values.map(v => v.key)
children.forEach(child => { // children.forEach(child => {
if (!child) { // if (!child) {
return // return
} // }
if (getSlotOptions(child).isSelectOptGroup) { // if (getSlotOptions(child).isSelectOptGroup) {
nextValues = this.addTitleToValue(child.componentOptions.children, nextValues) // nextValues = this.addTitleToValue(child.componentOptions.children, nextValues)
} else { // } else {
const value = getValuePropValue(child) // const value = getValuePropValue(child)
const valueIndex = keys.indexOf(value) // const valueIndex = keys.indexOf(value)
if (valueIndex > -1) { // if (valueIndex > -1) {
nextValues[valueIndex].title = getValue(child, 'title') // nextValues[valueIndex].title = getValue(child, 'title')
} // }
} // }
}) // })
return nextValues // return nextValues
}, // },
removeSelected (selectedKey) { removeSelected (selectedKey) {
const props = this.$props const props = this.$props
@ -1043,32 +1013,6 @@ export default {
return nextValue return nextValue
}, },
adjustOpenState () {
if (this.skipAdjustOpen) {
return
}
const { $props, showSearch } = this
let sOpen = this.sOpen
let options = []
// If hidden menu due to no options, then it should be calculated again
if (sOpen || this.hiddenForNoOptions) {
options = this.renderFilterOptions()
}
this._options = options
if (isMultipleOrTagsOrCombobox($props) || !showSearch) {
if (sOpen && !options.length) {
sOpen = false
this.hiddenForNoOptions = true
}
// Keep menu open if there are options and hidden for no options before
if (this.hiddenForNoOptions && options.length) {
sOpen = true
this.hiddenForNoOptions = false
}
}
this.sOpen = sOpen
},
getOptionsAndOpenStatus () { getOptionsAndOpenStatus () {
let sOpen = this.sOpen let sOpen = this.sOpen
if (this.skipAdjustOpen) { if (this.skipAdjustOpen) {
@ -1345,7 +1289,7 @@ export default {
if (isMultipleOrTags(props)) { if (isMultipleOrTags(props)) {
selectedValueNodes = limitedCountValue.map(singleValue => { selectedValueNodes = limitedCountValue.map(singleValue => {
let content = this.labelMap.get(singleValue.key) let content = this.labelMap.get(singleValue.key)
const title = this.titleMap.get(singleValue.title) || content const title = this.titleMap.get(singleValue.key) || content
if ( if (
maxTagTextLength && maxTagTextLength &&
typeof content === 'string' && typeof content === 'string' &&
@ -1487,8 +1431,16 @@ export default {
}, },
render () { render () {
this.labelMap = new Map() // label and title
this.titleMap = new Map() const labelArr = []
const titleArr = []
this.sValue.forEach(({ key }) => {
labelArr.push([key, this.labelMap.get(key)])
titleArr.push([key, this.titleMap.get(key)])
})
this.labelMap = new Map(labelArr)
this.titleMap = new Map(titleArr)
this.updateLabelAndTitleMap(this.$slots.default) this.updateLabelAndTitleMap(this.$slots.default)
const props = this.$props const props = this.$props
const multiple = isMultipleOrTags(props) const multiple = isMultipleOrTags(props)

@ -3,7 +3,7 @@ const AsyncComp = () => {
const hashs = window.location.hash.split('/') const hashs = window.location.hash.split('/')
const d = hashs[hashs.length - 1] const d = hashs[hashs.length - 1]
return { return {
component: import(`../components/vc-select/demo/single.vue`), component: import(`../components/vc-select/demo/${d}.vue`),
} }
} }
export default [ export default [

20
package-lock.json generated

@ -6848,6 +6848,26 @@
"dev": true, "dev": true,
"optional": true "optional": true
}, },
"jsonp": {
"version": "0.2.1",
"resolved": "http://registry.npm.taobao.org/jsonp/download/jsonp-0.2.1.tgz",
"integrity": "sha1-pltPoPEL2nGaBUQep7lMVfPhW64=",
"dev": true,
"requires": {
"debug": "2.6.9"
},
"dependencies": {
"debug": {
"version": "2.6.9",
"resolved": "http://registry.npm.taobao.org/debug/download/debug-2.6.9.tgz",
"integrity": "sha1-XRKFFd8TT/Mn6QpMk/Tgd6U2NB8=",
"dev": true,
"requires": {
"ms": "2.0.0"
}
}
}
},
"jsprim": { "jsprim": {
"version": "1.4.1", "version": "1.4.1",
"resolved": "https://registry.npmjs.org/jsprim/-/jsprim-1.4.1.tgz", "resolved": "https://registry.npmjs.org/jsprim/-/jsprim-1.4.1.tgz",

Loading…
Cancel
Save