From e4ce99177deb8806eedee55dfa785a9eb2d00603 Mon Sep 17 00:00:00 2001 From: 梁灏 Date: Mon, 24 Oct 2016 14:22:33 +0800 Subject: [PATCH] update Select component --- components/select/option-group.vue | 3 +-- components/select/select.vue | 54 ++++++++++++++++++++++++++++++++++++++++++++++++------ local/routers/select.vue | 44 +++++++++++++++++++++----------------------- styles/components/select.less | 11 +++++++++++ 4 files changed, 81 insertions(+), 31 deletions(-) diff --git a/components/select/option-group.vue b/components/select/option-group.vue index f3055fd..e0c5d7b 100644 --- a/components/select/option-group.vue +++ b/components/select/option-group.vue @@ -18,8 +18,7 @@ }, data () { return { - prefixCls: prefixCls, - hidden: false // for search + prefixCls: prefixCls } } } diff --git a/components/select/select.vue b/components/select/select.vue index 39ce2f3..61a1f5a 100644 --- a/components/select/select.vue +++ b/components/select/select.vue @@ -12,17 +12,21 @@ {{ selectedSingle }} + @blur="handleBlur" + @keydown="resetInputState" + @keydown.delete="handleInputDelete" + v-el:input> - + + @@ -85,7 +89,8 @@ selectedMultiple: [], focusIndex: 0, query: '', - inputLength: 20 + inputLength: 20, + notFound: false } }, computed: { @@ -124,7 +129,11 @@ let style = {}; if (this.multiple) { - style.width = `${this.inputLength}px`; + if (this.showPlaceholder) { + style.width = '100%'; + } else { + style.width = `${this.inputLength}px`; + } } return style; @@ -245,6 +254,12 @@ return false; } this.model.splice(index, 1); + + if (this.filterable && this.visible) { + this.$els.input.focus(); + } + + this.$broadcast('on-update-popper'); }, // to select option for single toggleSingleSelected (value, init = false) { @@ -404,6 +419,14 @@ } } }, 300); + }, + resetInputState () { + this.inputLength = this.$els.input.value.length * 12 + 20; + }, + handleInputDelete () { + if (this.multiple && this.model.length && this.query === '') { + this.removeTag(this.model.length - 1); + } } }, ready () { @@ -423,6 +446,9 @@ }, visible (val) { if (val) { + if (this.multiple && this.filterable) { + this.$els.input.focus(); + } this.$broadcast('on-update-popper'); } else { @@ -430,6 +456,16 @@ }, query (val) { this.$broadcast('on-query-change', val); + let is_hidden = true; + + this.$nextTick(() => { + this.findChild((child) => { + if (!child.hidden) { + is_hidden = false; + } + }); + this.notFound = is_hidden; + }); } }, events: { @@ -443,6 +479,12 @@ this.removeTag(index); } else { this.model.push(value); + this.$broadcast('on-update-popper'); + } + + if (this.filterable) { + this.query = ''; + this.$els.input.focus(); } } else { this.model = value; diff --git a/local/routers/select.vue b/local/routers/select.vue index 7d07926..1bd88d1 100644 --- a/local/routers/select.vue +++ b/local/routers/select.vue @@ -4,7 +4,7 @@ {{ city | json }}

- + 北京市 上海市2 @@ -13,31 +13,16 @@ 南京市 杭州市 + 黑龙江市 - 黑龙江市 - - 北京市 - 上海市2 - 深圳市 - - - 南京市 - 杭州市 - - 黑龙江市 - - 北京市 - 上海市2 - 深圳市 - - - 南京市 - 杭州市 + + 嘉峪关市 + 兰州市 + 北京西 - 黑龙江市 - + 北京 上海市 深圳市 @@ -51,6 +36,19 @@ e市 + + 北京2 + 上海市 + 深圳市 + 广州市 + 石家庄市 + a1市 + b2市 + c1市 + d2市 + e1市 + + 北京2 上海市 @@ -84,7 +82,7 @@ return { city: '', focus: '', - focus2: ['beijing', 'guangzhou', 'b'] + focus2: ['beijing'] // focus2: [] } }, diff --git a/styles/components/select.less b/styles/components/select.less index 5b14788..d346311 100644 --- a/styles/components/select.less +++ b/styles/components/select.less @@ -163,6 +163,17 @@ &-small &-input{ height: @input-height-small; } + + &-multiple &-input{ + height: 25px; + line-height: 28px; + padding: 0 0 0 6px; + } + + &-not-found{ + text-align: center; + color: @btn-disable-color; + } } .@{select-item-prefix-cls} { -- libgit2 0.21.4