Commit 2739fc29cc959772d8750a4d1a3f47a09e7f4504
1 parent
707898f2
Select add prefix prop and slot. close #5477
Showing
4 changed files
with
73 additions
and
8 deletions
Show diff stats
examples/routers/select.vue
| 1 | 1 | <template> |
| 2 | - <div style="margin: 200px;"> | |
| 3 | - <Select size="small" v-model="model10" multiple style="width:260px"> | |
| 2 | + <div style="margin: 100px;"> | |
| 3 | + <Select v-model="model1" style="width:200px" prefix="ios-albums"> | |
| 4 | 4 | <Option v-for="item in cityList" :value="item.value" :key="item.value">{{ item.label }}</Option> |
| 5 | 5 | </Select> |
| 6 | - <Select v-model="model10" multiple style="width:260px"> | |
| 6 | + | |
| 7 | + <Select v-model="model10" multiple style="width:260px" prefix="ios-albums"> | |
| 7 | 8 | <Option v-for="item in cityList" :value="item.value" :key="item.value">{{ item.label }}</Option> |
| 8 | 9 | </Select> |
| 9 | - <Select size="large" v-model="model10" multiple style="width:260px"> | |
| 10 | + | |
| 11 | + <br><br> | |
| 12 | + | |
| 13 | + <Select v-model="model1" style="width:200px"> | |
| 14 | + <Icon type="ios-alarm" slot="prefix" color="red" /> | |
| 15 | + <Option v-for="item in cityList" :value="item.value" :key="item.value">{{ item.label }}</Option> | |
| 16 | + </Select> | |
| 17 | + | |
| 18 | + <Select v-model="model1" style="width:200px"> | |
| 19 | + <Avatar src="https://dev-file.iviewui.com/userinfoPDvn9gKWYihR24SpgC319vXY8qniCqj4/avatar" slot="prefix" size="small" /> | |
| 20 | + <Option v-for="item in cityList" :value="item.value" :key="item.value">{{ item.label }}</Option> | |
| 21 | + </Select> | |
| 22 | + | |
| 23 | + <Select v-model="model10" multiple style="width:260px" prefix="ios-albums"> | |
| 24 | + <Option v-for="item in cityList" :value="item.value" :key="item.value">{{ item.label }}</Option> | |
| 25 | + </Select> | |
| 26 | + | |
| 27 | + <br><br> | |
| 28 | + | |
| 29 | + <Select size="small" v-model="model1" style="width:200px" prefix="ios-albums"> | |
| 30 | + <Option v-for="item in cityList" :value="item.value" :key="item.value">{{ item.label }}</Option> | |
| 31 | + </Select> | |
| 32 | + | |
| 33 | + <Select size="small" v-model="model10" multiple style="width:260px" prefix="ios-albums"> | |
| 34 | + <Option v-for="item in cityList" :value="item.value" :key="item.value">{{ item.label }}</Option> | |
| 35 | + </Select> | |
| 36 | + | |
| 37 | + <br><br> | |
| 38 | + | |
| 39 | + <Select size="large" v-model="model1" style="width:200px" prefix="ios-albums"> | |
| 40 | + <Option v-for="item in cityList" :value="item.value" :key="item.value">{{ item.label }}</Option> | |
| 41 | + </Select> | |
| 42 | + | |
| 43 | + <Select size="large" v-model="model10" multiple style="width:260px" prefix="ios-albums"> | |
| 10 | 44 | <Option v-for="item in cityList" :value="item.value" :key="item.value">{{ item.label }}</Option> |
| 11 | 45 | </Select> |
| 12 | 46 | </div> |
| ... | ... | @@ -22,7 +56,7 @@ |
| 22 | 56 | }, |
| 23 | 57 | { |
| 24 | 58 | value: 'London', |
| 25 | - label: 'LondonLondonLondonLondonLondonLondonLondonLondonLondonLondonLondonLondonLondonLondonLondonLondonLondonLondon' | |
| 59 | + label: 'London' | |
| 26 | 60 | }, |
| 27 | 61 | { |
| 28 | 62 | value: 'Sydney', |
| ... | ... | @@ -41,7 +75,8 @@ |
| 41 | 75 | label: 'Canberra' |
| 42 | 76 | } |
| 43 | 77 | ], |
| 44 | - model10: ['New York', 'London'] | |
| 78 | + model1: '', | |
| 79 | + model10: [] | |
| 45 | 80 | } |
| 46 | 81 | } |
| 47 | 82 | } | ... | ... |
src/components/select/select-head.vue
| 1 | 1 | <template> |
| 2 | 2 | <div @click="onHeaderClick"> |
| 3 | + <span :class="[prefixCls + '-prefix']" v-if="$slots.prefix || prefix"> | |
| 4 | + <slot name="prefix"> | |
| 5 | + <Icon :type="prefix" v-if="prefix" /> | |
| 6 | + </slot> | |
| 7 | + </span> | |
| 3 | 8 | <div class="ivu-tag ivu-tag-checked" v-for="item in selectedMultiple"> |
| 4 | 9 | <span class="ivu-tag-text">{{ item.label }}</span> |
| 5 | 10 | <Icon type="ios-close" @click.native.stop="removeTag(item)"></Icon> |
| ... | ... | @@ -77,7 +82,10 @@ |
| 77 | 82 | queryProp: { |
| 78 | 83 | type: String, |
| 79 | 84 | default: '' |
| 80 | - } | |
| 85 | + }, | |
| 86 | + prefix: { | |
| 87 | + type: String | |
| 88 | + }, | |
| 81 | 89 | }, |
| 82 | 90 | data () { |
| 83 | 91 | return { |
| ... | ... | @@ -92,6 +100,7 @@ |
| 92 | 100 | singleDisplayClasses(){ |
| 93 | 101 | const {filterable, multiple, showPlaceholder} = this; |
| 94 | 102 | return [{ |
| 103 | + [prefixCls + '-head-with-prefix']: this.$slots.prefix || this.prefix, | |
| 95 | 104 | [prefixCls + '-placeholder']: showPlaceholder && !filterable, |
| 96 | 105 | [prefixCls + '-selected-value']: !showPlaceholder && !multiple && !filterable, |
| 97 | 106 | }]; | ... | ... |
src/components/select/select.vue
| ... | ... | @@ -33,6 +33,7 @@ |
| 33 | 33 | :multiple="multiple" |
| 34 | 34 | :values="values" |
| 35 | 35 | :clearable="canBeCleared" |
| 36 | + :prefix="prefix" | |
| 36 | 37 | :disabled="disabled" |
| 37 | 38 | :remote="remote" |
| 38 | 39 | :input-element-id="elementId" |
| ... | ... | @@ -44,7 +45,9 @@ |
| 44 | 45 | @on-input-focus="isFocused = true" |
| 45 | 46 | @on-input-blur="isFocused = false" |
| 46 | 47 | @on-clear="clearSingleSelect" |
| 47 | - /> | |
| 48 | + > | |
| 49 | + <slot name="prefix" slot="prefix"></slot> | |
| 50 | + </select-head> | |
| 48 | 51 | </slot> |
| 49 | 52 | </div> |
| 50 | 53 | <transition name="transition-drop"> |
| ... | ... | @@ -235,6 +238,9 @@ |
| 235 | 238 | transferClassName: { |
| 236 | 239 | type: String |
| 237 | 240 | }, |
| 241 | + prefix: { | |
| 242 | + type: String | |
| 243 | + }, | |
| 238 | 244 | }, |
| 239 | 245 | mounted(){ |
| 240 | 246 | this.$on('on-select-selected', this.onOptionClick); | ... | ... |
src/styles/components/select.less
| ... | ... | @@ -256,6 +256,21 @@ |
| 256 | 256 | & &-dropdown{ |
| 257 | 257 | width: auto; |
| 258 | 258 | } |
| 259 | + | |
| 260 | + &-prefix{ | |
| 261 | + display: inline-block; | |
| 262 | + vertical-align: middle; | |
| 263 | + } | |
| 264 | + &-head-with-prefix{ | |
| 265 | + display: inline-block !important; | |
| 266 | + vertical-align: middle; | |
| 267 | + } | |
| 268 | + &-single &-prefix{ | |
| 269 | + padding-left: 4px; | |
| 270 | + } | |
| 271 | + &-single &-head-with-prefix, &-multiple &-head-with-prefix{ | |
| 272 | + padding-left: 0 !important; | |
| 273 | + } | |
| 259 | 274 | } |
| 260 | 275 | |
| 261 | 276 | .select-item(@select-prefix-cls, @select-item-prefix-cls); | ... | ... |