@penggy/element-ui 2.4.11 → 2.4.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (334) hide show
  1. package/lib/autocomplete.js +8 -8
  2. package/lib/carousel.js +1 -1
  3. package/lib/cascader.js +9 -9
  4. package/lib/checkbox-button.js +1 -1
  5. package/lib/checkbox-group.js +1 -1
  6. package/lib/checkbox.js +1 -1
  7. package/lib/collapse-item.js +3 -3
  8. package/lib/color-picker.js +6 -6
  9. package/lib/date-picker.js +17 -17
  10. package/lib/dialog.js +3 -3
  11. package/lib/directives/repeat-click.js +1 -1
  12. package/lib/dropdown-item.js +1 -1
  13. package/lib/dropdown-menu.js +1 -1
  14. package/lib/dropdown.js +6 -6
  15. package/lib/element-ui.common.js +443 -91
  16. package/lib/form-item.js +3 -3
  17. package/lib/form.js +1 -1
  18. package/lib/index.js +1 -1
  19. package/lib/input-number.js +3 -3
  20. package/lib/input.js +4 -4
  21. package/lib/loading.js +4 -4
  22. package/lib/locale/format.js +11 -11
  23. package/lib/locale/index.js +1 -1
  24. package/lib/menu-item.js +2 -2
  25. package/lib/menu.js +28 -28
  26. package/lib/message-box.js +9 -9
  27. package/lib/message.js +2 -2
  28. package/lib/mixins/locale.js +1 -1
  29. package/lib/mixins/migrating.js +20 -20
  30. package/lib/notification.js +2 -2
  31. package/lib/option-group.js +1 -1
  32. package/lib/option.js +2 -2
  33. package/lib/pagination.js +5 -5
  34. package/lib/popover.js +3 -3
  35. package/lib/radio-button.js +1 -1
  36. package/lib/radio-group.js +1 -1
  37. package/lib/radio.js +1 -1
  38. package/lib/rate.js +2 -2
  39. package/lib/scrollbar.js +4 -4
  40. package/lib/select.js +13 -13
  41. package/lib/slider.js +3 -3
  42. package/lib/steps.js +1 -1
  43. package/lib/submenu.js +3 -3
  44. package/lib/switch.js +2 -2
  45. package/lib/table-column.js +4 -4
  46. package/lib/table.js +14 -14
  47. package/lib/tabs.js +1 -1
  48. package/lib/time-picker.js +15 -15
  49. package/lib/time-select.js +14 -14
  50. package/lib/tooltip.js +4 -4
  51. package/lib/transfer.js +7 -7
  52. package/lib/transitions/collapse-transition.js +1 -1
  53. package/lib/tree.js +6 -6
  54. package/lib/upload.js +3 -3
  55. package/lib/utils/after-leave.js +7 -7
  56. package/lib/utils/aria-dialog.js +16 -16
  57. package/lib/utils/aria-utils.js +25 -25
  58. package/lib/utils/clickoutside.js +8 -8
  59. package/lib/utils/date.js +37 -37
  60. package/lib/utils/popper.js +321 -321
  61. package/lib/utils/popup/index.js +2 -2
  62. package/lib/utils/popup/popup-manager.js +1 -1
  63. package/lib/utils/vdom.js +1 -1
  64. package/lib/utils/vue-popper.js +8 -8
  65. package/package.json +1 -1
  66. package/packages/alert/index.js +8 -8
  67. package/packages/alert/src/main.vue +88 -88
  68. package/packages/aside/index.js +8 -8
  69. package/packages/aside/src/main.vue +20 -20
  70. package/packages/autocomplete/index.js +8 -8
  71. package/packages/autocomplete/src/autocomplete-suggestions.vue +76 -76
  72. package/packages/autocomplete/src/autocomplete.vue +269 -269
  73. package/packages/badge/index.js +8 -8
  74. package/packages/badge/src/main.vue +53 -53
  75. package/packages/breadcrumb/index.js +8 -8
  76. package/packages/breadcrumb/src/breadcrumb-item.vue +41 -41
  77. package/packages/breadcrumb/src/breadcrumb.vue +34 -34
  78. package/packages/breadcrumb-item/index.js +8 -8
  79. package/packages/button/index.js +8 -8
  80. package/packages/button/src/button-group.vue +10 -10
  81. package/packages/button/src/button.vue +78 -78
  82. package/packages/button-group/index.js +8 -8
  83. package/packages/card/index.js +8 -8
  84. package/packages/card/src/main.vue +23 -23
  85. package/packages/carousel/index.js +8 -8
  86. package/packages/carousel/src/item.vue +114 -114
  87. package/packages/carousel/src/main.vue +262 -262
  88. package/packages/carousel-item/index.js +8 -8
  89. package/packages/cascader/index.js +8 -8
  90. package/packages/cascader/src/main.vue +456 -456
  91. package/packages/cascader/src/menu.vue +376 -376
  92. package/packages/checkbox/index.js +8 -8
  93. package/packages/checkbox/src/checkbox-button.vue +191 -191
  94. package/packages/checkbox/src/checkbox-group.vue +48 -48
  95. package/packages/checkbox/src/checkbox.vue +219 -219
  96. package/packages/checkbox-button/index.js +8 -8
  97. package/packages/checkbox-group/index.js +8 -8
  98. package/packages/col/index.js +9 -9
  99. package/packages/col/src/col.js +71 -71
  100. package/packages/collapse/index.js +9 -9
  101. package/packages/collapse/src/collapse-item.vue +113 -113
  102. package/packages/collapse/src/collapse.vue +73 -73
  103. package/packages/collapse-item/index.js +8 -8
  104. package/packages/color-picker/index.js +8 -8
  105. package/packages/color-picker/src/color.js +316 -316
  106. package/packages/color-picker/src/components/alpha-slider.vue +132 -132
  107. package/packages/color-picker/src/components/hue-slider.vue +123 -123
  108. package/packages/color-picker/src/components/picker-dropdown.vue +121 -121
  109. package/packages/color-picker/src/components/predefine.vue +60 -60
  110. package/packages/color-picker/src/components/sv-panel.vue +100 -100
  111. package/packages/color-picker/src/draggable.js +36 -36
  112. package/packages/color-picker/src/main.vue +188 -188
  113. package/packages/container/index.js +8 -8
  114. package/packages/container/src/main.vue +33 -33
  115. package/packages/date-picker/index.js +8 -8
  116. package/packages/date-picker/src/basic/date-table.vue +437 -437
  117. package/packages/date-picker/src/basic/month-table.vue +105 -105
  118. package/packages/date-picker/src/basic/time-spinner.vue +301 -301
  119. package/packages/date-picker/src/basic/year-table.vue +101 -101
  120. package/packages/date-picker/src/panel/date-range.vue +640 -640
  121. package/packages/date-picker/src/panel/date.vue +579 -579
  122. package/packages/date-picker/src/panel/time-range.vue +248 -248
  123. package/packages/date-picker/src/panel/time-select.vue +177 -177
  124. package/packages/date-picker/src/panel/time.vue +186 -186
  125. package/packages/date-picker/src/picker/date-picker.js +40 -40
  126. package/packages/date-picker/src/picker/time-picker.js +39 -39
  127. package/packages/date-picker/src/picker/time-select.js +21 -21
  128. package/packages/date-picker/src/picker.vue +924 -924
  129. package/packages/date-picker/src/util/index.js +273 -273
  130. package/packages/dialog/index.js +8 -8
  131. package/packages/dialog/src/component.vue +201 -201
  132. package/packages/dropdown/index.js +8 -8
  133. package/packages/dropdown/src/dropdown-item.vue +35 -35
  134. package/packages/dropdown/src/dropdown-menu.vue +60 -60
  135. package/packages/dropdown/src/dropdown.vue +271 -271
  136. package/packages/dropdown-item/index.js +8 -8
  137. package/packages/dropdown-menu/index.js +8 -8
  138. package/packages/footer/index.js +8 -8
  139. package/packages/footer/src/main.vue +20 -20
  140. package/packages/form/index.js +8 -8
  141. package/packages/form/src/form-item.vue +290 -290
  142. package/packages/form/src/form.vue +148 -148
  143. package/packages/form-item/index.js +8 -8
  144. package/packages/header/index.js +8 -8
  145. package/packages/header/src/main.vue +20 -20
  146. package/packages/icon/index.js +8 -8
  147. package/packages/icon/src/icon.vue +13 -13
  148. package/packages/input/index.js +8 -8
  149. package/packages/input/src/calcTextareaHeight.js +104 -104
  150. package/packages/input/src/input.vue +349 -349
  151. package/packages/input-number/index.js +8 -8
  152. package/packages/input-number/src/input-number.vue +255 -255
  153. package/packages/loading/index.js +11 -11
  154. package/packages/loading/src/directive.js +128 -128
  155. package/packages/loading/src/index.js +106 -106
  156. package/packages/loading/src/loading.vue +41 -41
  157. package/packages/main/index.js +8 -8
  158. package/packages/main/src/main.vue +12 -12
  159. package/packages/menu/index.js +8 -8
  160. package/packages/menu/src/menu-item-group.vue +45 -45
  161. package/packages/menu/src/menu-item.vue +112 -112
  162. package/packages/menu/src/menu-mixin.js +44 -44
  163. package/packages/menu/src/menu.vue +311 -311
  164. package/packages/menu/src/submenu.vue +335 -335
  165. package/packages/menu-item/index.js +8 -8
  166. package/packages/menu-item-group/index.js +8 -8
  167. package/packages/message/index.js +2 -2
  168. package/packages/message/src/main.js +72 -72
  169. package/packages/message/src/main.vue +112 -112
  170. package/packages/message-box/index.js +2 -2
  171. package/packages/message-box/src/main.js +216 -216
  172. package/packages/message-box/src/main.vue +327 -327
  173. package/packages/notification/index.js +2 -2
  174. package/packages/notification/src/main.js +93 -93
  175. package/packages/notification/src/main.vue +152 -152
  176. package/packages/option/index.js +8 -8
  177. package/packages/option-group/index.js +8 -8
  178. package/packages/pagination/index.js +8 -8
  179. package/packages/pagination/src/pager.vue +163 -163
  180. package/packages/pagination/src/pagination.js +430 -430
  181. package/packages/popover/index.js +14 -14
  182. package/packages/popover/src/directive.js +20 -20
  183. package/packages/popover/src/main.vue +207 -207
  184. package/packages/progress/index.js +8 -8
  185. package/packages/progress/src/progress.vue +138 -138
  186. package/packages/radio/index.js +8 -8
  187. package/packages/radio/src/radio-button.vue +114 -114
  188. package/packages/radio/src/radio-group.vue +100 -100
  189. package/packages/radio/src/radio.vue +126 -126
  190. package/packages/radio-button/index.js +8 -8
  191. package/packages/radio-group/index.js +8 -8
  192. package/packages/rate/index.js +8 -8
  193. package/packages/rate/src/main.vue +350 -350
  194. package/packages/row/index.js +9 -9
  195. package/packages/row/src/row.js +47 -47
  196. package/packages/scrollbar/index.js +8 -8
  197. package/packages/scrollbar/src/bar.js +88 -88
  198. package/packages/scrollbar/src/main.js +130 -130
  199. package/packages/scrollbar/src/util.js +34 -34
  200. package/packages/select/index.js +8 -8
  201. package/packages/select/src/navigation-mixin.js +54 -54
  202. package/packages/select/src/option-group.vue +60 -60
  203. package/packages/select/src/option.vue +159 -159
  204. package/packages/select/src/select-dropdown.vue +74 -74
  205. package/packages/select/src/select.vue +878 -878
  206. package/packages/slider/index.js +8 -8
  207. package/packages/slider/src/button.vue +235 -235
  208. package/packages/slider/src/main.vue +385 -385
  209. package/packages/spinner/index.js +8 -8
  210. package/packages/spinner/src/spinner.vue +27 -27
  211. package/packages/step/index.js +8 -8
  212. package/packages/steps/index.js +8 -8
  213. package/packages/steps/src/step.vue +180 -180
  214. package/packages/steps/src/steps.vue +68 -68
  215. package/packages/submenu/index.js +8 -8
  216. package/packages/switch/index.js +9 -9
  217. package/packages/switch/src/component.vue +163 -163
  218. package/packages/tab-pane/index.js +8 -8
  219. package/packages/table/index.js +8 -8
  220. package/packages/table/src/dropdown.js +28 -28
  221. package/packages/table/src/filter-panel.vue +203 -203
  222. package/packages/table/src/layout-observer.js +68 -68
  223. package/packages/table/src/table-body.js +392 -392
  224. package/packages/table/src/table-column.js +462 -462
  225. package/packages/table/src/table-footer.js +147 -147
  226. package/packages/table/src/table-header.js +522 -522
  227. package/packages/table/src/table-layout.js +231 -231
  228. package/packages/table/src/table-store.js +657 -657
  229. package/packages/table/src/table.vue +660 -660
  230. package/packages/table/src/util.js +122 -122
  231. package/packages/table-column/index.js +8 -8
  232. package/packages/tabs/index.js +8 -8
  233. package/packages/tabs/src/tab-bar.vue +57 -57
  234. package/packages/tabs/src/tab-nav.vue +280 -280
  235. package/packages/tabs/src/tab-pane.vue +58 -58
  236. package/packages/tabs/src/tabs.vue +185 -185
  237. package/packages/tag/index.js +8 -8
  238. package/packages/tag/src/tag.vue +39 -39
  239. package/packages/time-picker/index.js +8 -8
  240. package/packages/time-select/index.js +8 -8
  241. package/packages/tooltip/index.js +8 -8
  242. package/packages/tooltip/src/main.js +216 -216
  243. package/packages/transfer/index.js +8 -8
  244. package/packages/transfer/src/main.vue +231 -231
  245. package/packages/transfer/src/transfer-panel.vue +251 -251
  246. package/packages/tree/index.js +8 -8
  247. package/packages/tree/src/model/node.js +481 -481
  248. package/packages/tree/src/model/tree-store.js +333 -333
  249. package/packages/tree/src/model/util.js +27 -27
  250. package/packages/tree/src/tree-node.vue +277 -277
  251. package/packages/tree/src/tree.vue +495 -495
  252. package/packages/upload/index.js +8 -8
  253. package/packages/upload/src/ajax.js +85 -85
  254. package/packages/upload/src/index.vue +315 -315
  255. package/packages/upload/src/upload-dragger.vue +70 -70
  256. package/packages/upload/src/upload-list.vue +103 -103
  257. package/packages/upload/src/upload.vue +211 -211
  258. package/src/directives/mousewheel.js +18 -18
  259. package/src/directives/repeat-click.js +24 -24
  260. package/src/index.js +1 -1
  261. package/src/locale/format.js +46 -46
  262. package/src/locale/index.js +48 -48
  263. package/src/locale/lang/af-ZA.js +109 -109
  264. package/src/locale/lang/ar.js +108 -108
  265. package/src/locale/lang/bg.js +109 -109
  266. package/src/locale/lang/ca.js +108 -108
  267. package/src/locale/lang/cs-CZ.js +111 -111
  268. package/src/locale/lang/da.js +108 -108
  269. package/src/locale/lang/de.js +110 -110
  270. package/src/locale/lang/ee.js +109 -109
  271. package/src/locale/lang/el.js +109 -109
  272. package/src/locale/lang/en.js +109 -109
  273. package/src/locale/lang/es.js +108 -108
  274. package/src/locale/lang/eu.js +109 -109
  275. package/src/locale/lang/fa.js +109 -109
  276. package/src/locale/lang/fi.js +109 -109
  277. package/src/locale/lang/fr.js +108 -108
  278. package/src/locale/lang/he.js +109 -109
  279. package/src/locale/lang/hu.js +108 -108
  280. package/src/locale/lang/id.js +109 -109
  281. package/src/locale/lang/it.js +108 -108
  282. package/src/locale/lang/ja.js +109 -109
  283. package/src/locale/lang/km.js +109 -109
  284. package/src/locale/lang/ko.js +109 -109
  285. package/src/locale/lang/ku.js +109 -109
  286. package/src/locale/lang/kz.js +109 -109
  287. package/src/locale/lang/lt.js +109 -109
  288. package/src/locale/lang/lv.js +109 -109
  289. package/src/locale/lang/mn.js +109 -109
  290. package/src/locale/lang/nb-NO.js +108 -108
  291. package/src/locale/lang/nl.js +109 -109
  292. package/src/locale/lang/pl.js +109 -109
  293. package/src/locale/lang/pt-br.js +109 -109
  294. package/src/locale/lang/pt.js +109 -109
  295. package/src/locale/lang/ro.js +109 -109
  296. package/src/locale/lang/ru-RU.js +109 -109
  297. package/src/locale/lang/sk.js +111 -111
  298. package/src/locale/lang/sl.js +109 -109
  299. package/src/locale/lang/sr.js +109 -109
  300. package/src/locale/lang/sv-SE.js +109 -109
  301. package/src/locale/lang/ta.js +108 -108
  302. package/src/locale/lang/th.js +109 -109
  303. package/src/locale/lang/tk.js +109 -109
  304. package/src/locale/lang/tr-TR.js +109 -109
  305. package/src/locale/lang/ua.js +109 -109
  306. package/src/locale/lang/ug-CN.js +109 -109
  307. package/src/locale/lang/vi.js +109 -109
  308. package/src/locale/lang/zh-CN.js +109 -109
  309. package/src/locale/lang/zh-TW.js +109 -109
  310. package/src/mixins/emitter.js +33 -33
  311. package/src/mixins/focus.js +9 -9
  312. package/src/mixins/locale.js +9 -9
  313. package/src/mixins/migrating.js +51 -51
  314. package/src/transitions/collapse-transition.js +77 -77
  315. package/src/utils/after-leave.js +27 -27
  316. package/src/utils/aria-dialog.js +90 -90
  317. package/src/utils/aria-utils.js +121 -121
  318. package/src/utils/clickoutside.js +76 -76
  319. package/src/utils/date.js +344 -344
  320. package/src/utils/dom.js +174 -174
  321. package/src/utils/menu/aria-menubar.js +14 -14
  322. package/src/utils/menu/aria-menuitem.js +49 -49
  323. package/src/utils/menu/aria-submenu.js +59 -59
  324. package/src/utils/merge.js +15 -15
  325. package/src/utils/popper.js +1276 -1276
  326. package/src/utils/popup/index.js +226 -226
  327. package/src/utils/popup/popup-manager.js +194 -194
  328. package/src/utils/resize-event.js +35 -35
  329. package/src/utils/scroll-into-view.js +27 -27
  330. package/src/utils/scrollbar-width.js +29 -29
  331. package/src/utils/shared.js +7 -7
  332. package/src/utils/util.js +122 -122
  333. package/src/utils/vdom.js +9 -9
  334. package/src/utils/vue-popper.js +200 -200
@@ -1,878 +1,878 @@
1
- <template>
2
- <div
3
- class="el-select"
4
- :class="[selectSize ? 'el-select--' + selectSize : '']"
5
- @click.stop="toggleMenu"
6
- v-clickoutside="handleClose">
7
- <div
8
- class="el-select__tags"
9
- v-if="multiple"
10
- ref="tags"
11
- :style="{ 'max-width': inputWidth - 32 + 'px', width: '100%' }">
12
- <span v-if="collapseTags && selected.length">
13
- <el-tag
14
- :closable="!selectDisabled"
15
- :size="collapseTagSize"
16
- :hit="selected[0].hitState"
17
- type="info"
18
- @close="deleteTag($event, selected[0])"
19
- disable-transitions>
20
- <span class="el-select__tags-text">{{ selected[0].currentLabel }}</span>
21
- </el-tag>
22
- <el-tag
23
- v-if="selected.length > 1"
24
- :closable="false"
25
- :size="collapseTagSize"
26
- type="info"
27
- disable-transitions>
28
- <span class="el-select__tags-text">+ {{ selected.length - 1 }}</span>
29
- </el-tag>
30
- </span>
31
- <transition-group @after-leave="resetInputHeight" v-if="!collapseTags">
32
- <el-tag
33
- v-for="item in selected"
34
- :key="getValueKey(item)"
35
- :closable="!selectDisabled"
36
- :size="collapseTagSize"
37
- :hit="item.hitState"
38
- type="info"
39
- @close="deleteTag($event, item)"
40
- disable-transitions>
41
- <span class="el-select__tags-text">{{ item.currentLabel }}</span>
42
- </el-tag>
43
- </transition-group>
44
-
45
- <input
46
- type="text"
47
- class="el-select__input"
48
- :class="[selectSize ? `is-${ selectSize }` : '']"
49
- :disabled="selectDisabled"
50
- :autocomplete="autoComplete || autocomplete"
51
- @focus="handleFocus"
52
- @blur="softFocus = false"
53
- @click.stop
54
- @keyup="managePlaceholder"
55
- @keydown="resetInputState"
56
- @keydown.down.prevent="navigateOptions('next')"
57
- @keydown.up.prevent="navigateOptions('prev')"
58
- @keydown.enter.prevent="selectOption"
59
- @keydown.esc.stop.prevent="visible = false"
60
- @keydown.delete="deletePrevTag"
61
- @compositionstart="handleComposition"
62
- @compositionupdate="handleComposition"
63
- @compositionend="handleComposition"
64
- v-model="query"
65
- @input="debouncedQueryChange"
66
- v-if="filterable"
67
- :style="{ 'flex-grow': '1', width: inputLength / (inputWidth - 32) + '%', 'max-width': inputWidth - 42 + 'px' }"
68
- ref="input">
69
- </div>
70
- <el-input
71
- ref="reference"
72
- v-model="selectedLabel"
73
- type="text"
74
- :placeholder="currentPlaceholder"
75
- :name="name"
76
- :id="id"
77
- :autocomplete="autoComplete || autocomplete"
78
- :size="selectSize"
79
- :disabled="selectDisabled"
80
- :readonly="readonly"
81
- :validate-event="false"
82
- :class="{ 'is-focus': visible }"
83
- @focus="handleFocus"
84
- @blur="handleBlur"
85
- @keyup.native="debouncedOnInputChange"
86
- @keydown.native.down.stop.prevent="navigateOptions('next')"
87
- @keydown.native.up.stop.prevent="navigateOptions('prev')"
88
- @keydown.native.enter.prevent="selectOption"
89
- @keydown.native.esc.stop.prevent="visible = false"
90
- @keydown.native.tab="visible = false"
91
- @paste.native="debouncedOnInputChange"
92
- @mouseenter.native="inputHovering = true"
93
- @mouseleave.native="inputHovering = false">
94
- <template slot="prefix" v-if="$slots.prefix">
95
- <slot name="prefix"></slot>
96
- </template>
97
- <template slot="suffix">
98
- <i v-show="!showClose" :class="['el-select__caret', 'el-input__icon', 'el-icon-' + iconClass]"></i>
99
- <i v-if="showClose" class="el-select__caret el-input__icon el-icon-circle-close" @click="handleClearClick"></i>
100
- </template>
101
- </el-input>
102
- <transition
103
- name="el-zoom-in-top"
104
- @before-enter="handleMenuEnter"
105
- @after-leave="doDestroy">
106
- <el-select-menu
107
- ref="popper"
108
- :append-to-body="popperAppendToBody"
109
- v-show="visible && emptyText !== false">
110
- <el-scrollbar
111
- tag="ul"
112
- wrap-class="el-select-dropdown__wrap"
113
- view-class="el-select-dropdown__list"
114
- ref="scrollbar"
115
- :class="{ 'is-empty': !allowCreate && query && filteredOptionsCount === 0 }"
116
- v-show="options.length > 0 && !loading">
117
- <el-option
118
- :value="query"
119
- created
120
- v-if="showNewOption">
121
- </el-option>
122
- <slot></slot>
123
- </el-scrollbar>
124
- <p
125
- class="el-select-dropdown__empty"
126
- v-if="emptyText &&
127
- (!allowCreate || loading || (allowCreate && options.length === 0 ))">
128
- {{ emptyText }}
129
- </p>
130
- </el-select-menu>
131
- </transition>
132
- </div>
133
- </template>
134
-
135
- <script type="text/babel">
136
- import Emitter from 'element-ui/src/mixins/emitter';
137
- import Focus from 'element-ui/src/mixins/focus';
138
- import Locale from 'element-ui/src/mixins/locale';
139
- import ElInput from 'element-ui/packages/input';
140
- import ElSelectMenu from './select-dropdown.vue';
141
- import ElOption from './option.vue';
142
- import ElTag from 'element-ui/packages/tag';
143
- import ElScrollbar from 'element-ui/packages/scrollbar';
144
- import debounce from 'throttle-debounce/debounce';
145
- import Clickoutside from 'element-ui/src/utils/clickoutside';
146
- import { addResizeListener, removeResizeListener } from 'element-ui/src/utils/resize-event';
147
- import { t } from 'element-ui/src/locale';
148
- import scrollIntoView from 'element-ui/src/utils/scroll-into-view';
149
- import { getValueByPath } from 'element-ui/src/utils/util';
150
- import { valueEquals, isIE, isEdge } from 'element-ui/src/utils/util';
151
- import NavigationMixin from './navigation-mixin';
152
- import { isKorean } from 'element-ui/src/utils/shared';
153
-
154
- export default {
155
- mixins: [Emitter, Locale, Focus('reference'), NavigationMixin],
156
-
157
- name: 'ElSelect',
158
-
159
- componentName: 'ElSelect',
160
-
161
- inject: {
162
- elForm: {
163
- default: ''
164
- },
165
-
166
- elFormItem: {
167
- default: ''
168
- }
169
- },
170
-
171
- provide() {
172
- return {
173
- 'select': this
174
- };
175
- },
176
-
177
- computed: {
178
- _elFormItemSize() {
179
- return (this.elFormItem || {}).elFormItemSize;
180
- },
181
-
182
- readonly() {
183
- return !this.filterable || this.multiple || (!isIE() && !isEdge() && !this.visible);
184
- },
185
-
186
- showClose() {
187
- let hasValue = this.multiple
188
- ? Array.isArray(this.value) && this.value.length > 0
189
- : this.value !== undefined && this.value !== null && this.value !== '';
190
- let criteria = this.clearable &&
191
- !this.selectDisabled &&
192
- this.inputHovering &&
193
- hasValue;
194
- return criteria;
195
- },
196
-
197
- iconClass() {
198
- return this.remote && this.filterable ? '' : (this.visible ? 'arrow-up is-reverse' : 'arrow-up');
199
- },
200
-
201
- debounce() {
202
- return this.remote ? 300 : 0;
203
- },
204
-
205
- emptyText() {
206
- if (this.loading) {
207
- return this.loadingText || this.t('el.select.loading');
208
- } else {
209
- if (this.remote && this.query === '' && this.options.length === 0) return false;
210
- if (this.filterable && this.query && this.options.length > 0 && this.filteredOptionsCount === 0) {
211
- return this.noMatchText || this.t('el.select.noMatch');
212
- }
213
- if (this.options.length === 0) {
214
- return this.noDataText || this.t('el.select.noData');
215
- }
216
- }
217
- return null;
218
- },
219
-
220
- showNewOption() {
221
- let hasExistingOption = this.options.filter(option => !option.created)
222
- .some(option => option.currentLabel === this.query);
223
- return this.filterable && this.allowCreate && this.query !== '' && !hasExistingOption;
224
- },
225
-
226
- selectSize() {
227
- return this.size || this._elFormItemSize || (this.$ELEMENT || {}).size;
228
- },
229
-
230
- selectDisabled() {
231
- return this.disabled || (this.elForm || {}).disabled;
232
- },
233
-
234
- collapseTagSize() {
235
- return ['small', 'mini'].indexOf(this.selectSize) > -1
236
- ? 'mini'
237
- : 'small';
238
- }
239
- },
240
-
241
- components: {
242
- ElInput,
243
- ElSelectMenu,
244
- ElOption,
245
- ElTag,
246
- ElScrollbar
247
- },
248
-
249
- directives: { Clickoutside },
250
-
251
- props: {
252
- name: String,
253
- id: String,
254
- value: {
255
- required: true
256
- },
257
- autocomplete: {
258
- type: String,
259
- default: 'off'
260
- },
261
- /** @Deprecated in next major version */
262
- autoComplete: {
263
- type: String,
264
- validator(val) {
265
- process.env.NODE_ENV !== 'production' &&
266
- console.warn('[Element Warn][Select]\'auto-complete\' property will be deprecated in next major version. please use \'autocomplete\' instead.');
267
- return true;
268
- }
269
- },
270
- automaticDropdown: Boolean,
271
- size: String,
272
- disabled: Boolean,
273
- clearable: Boolean,
274
- filterable: Boolean,
275
- allowCreate: Boolean,
276
- loading: Boolean,
277
- popperClass: String,
278
- remote: Boolean,
279
- loadingText: String,
280
- noMatchText: String,
281
- noDataText: String,
282
- remoteMethod: Function,
283
- filterMethod: Function,
284
- multiple: Boolean,
285
- multipleLimit: {
286
- type: Number,
287
- default: 0
288
- },
289
- placeholder: {
290
- type: String,
291
- default() {
292
- return t('el.select.placeholder');
293
- }
294
- },
295
- defaultFirstOption: Boolean,
296
- reserveKeyword: Boolean,
297
- valueKey: {
298
- type: String,
299
- default: 'value'
300
- },
301
- collapseTags: Boolean,
302
- popperAppendToBody: {
303
- type: Boolean,
304
- default: true
305
- }
306
- },
307
-
308
- data() {
309
- return {
310
- options: [],
311
- cachedOptions: [],
312
- createdLabel: null,
313
- createdSelected: false,
314
- selected: this.multiple ? [] : {},
315
- inputLength: 20,
316
- inputWidth: 0,
317
- initialInputHeight: 0,
318
- cachedPlaceHolder: '',
319
- optionsCount: 0,
320
- filteredOptionsCount: 0,
321
- visible: false,
322
- softFocus: false,
323
- selectedLabel: '',
324
- hoverIndex: -1,
325
- query: '',
326
- previousQuery: null,
327
- inputHovering: false,
328
- currentPlaceholder: '',
329
- menuVisibleOnFocus: false,
330
- isOnComposition: false,
331
- isSilentBlur: false
332
- };
333
- },
334
-
335
- watch: {
336
- selectDisabled() {
337
- this.$nextTick(() => {
338
- this.resetInputHeight();
339
- });
340
- },
341
-
342
- placeholder(val) {
343
- this.cachedPlaceHolder = this.currentPlaceholder = val;
344
- },
345
-
346
- value(val, oldVal) {
347
- if (this.multiple) {
348
- this.resetInputHeight();
349
- if (val.length > 0 || (this.$refs.input && this.query !== '')) {
350
- this.currentPlaceholder = '';
351
- } else {
352
- this.currentPlaceholder = this.cachedPlaceHolder;
353
- }
354
- if (this.filterable && !this.reserveKeyword) {
355
- this.query = '';
356
- this.handleQueryChange(this.query);
357
- }
358
- }
359
- this.setSelected();
360
- if (this.filterable && !this.multiple) {
361
- this.inputLength = 20;
362
- }
363
- if (!valueEquals(val, oldVal)) {
364
- this.dispatch('ElFormItem', 'el.form.change', val);
365
- }
366
- },
367
-
368
- visible(val) {
369
- if (!val) {
370
- this.broadcast('ElSelectDropdown', 'destroyPopper');
371
- if (this.$refs.input) {
372
- this.$refs.input.blur();
373
- }
374
- this.query = '';
375
- this.previousQuery = null;
376
- this.selectedLabel = '';
377
- this.inputLength = 20;
378
- this.menuVisibleOnFocus = false;
379
- this.resetHoverIndex();
380
- this.$nextTick(() => {
381
- if (this.$refs.input &&
382
- this.$refs.input.value === '' &&
383
- this.selected.length === 0) {
384
- this.currentPlaceholder = this.cachedPlaceHolder;
385
- }
386
- });
387
- if (!this.multiple) {
388
- if (this.selected) {
389
- if (this.filterable && this.allowCreate &&
390
- this.createdSelected && this.createdLabel) {
391
- this.selectedLabel = this.createdLabel;
392
- } else {
393
- this.selectedLabel = this.selected.currentLabel;
394
- }
395
- if (this.filterable) this.query = this.selectedLabel;
396
- }
397
- }
398
- } else {
399
- this.broadcast('ElSelectDropdown', 'updatePopper');
400
- if (this.filterable) {
401
- this.query = this.remote ? '' : this.selectedLabel;
402
- this.handleQueryChange(this.query);
403
- if (this.multiple) {
404
- this.$refs.input.focus();
405
- } else {
406
- if (!this.remote) {
407
- this.broadcast('ElOption', 'queryChange', '');
408
- this.broadcast('ElOptionGroup', 'queryChange');
409
- }
410
- this.broadcast('ElInput', 'inputSelect');
411
- }
412
- }
413
- }
414
- this.$emit('visible-change', val);
415
- },
416
-
417
- options() {
418
- if (this.$isServer) return;
419
- this.$nextTick(() => {
420
- this.broadcast('ElSelectDropdown', 'updatePopper');
421
- });
422
- if (this.multiple) {
423
- this.resetInputHeight();
424
- }
425
- let inputs = this.$el.querySelectorAll('input');
426
- if ([].indexOf.call(inputs, document.activeElement) === -1) {
427
- this.setSelected();
428
- }
429
- if (this.defaultFirstOption && (this.filterable || this.remote) && this.filteredOptionsCount) {
430
- this.checkDefaultFirstOption();
431
- }
432
- }
433
- },
434
-
435
- methods: {
436
- handleComposition(event) {
437
- const text = event.target.value;
438
- if (event.type === 'compositionend') {
439
- this.isOnComposition = false;
440
- this.handleQueryChange(text);
441
- } else {
442
- const lastCharacter = text[text.length - 1] || '';
443
- this.isOnComposition = !isKorean(lastCharacter);
444
- }
445
- },
446
- handleQueryChange(val) {
447
- if (this.previousQuery === val || this.isOnComposition) return;
448
- if (
449
- this.previousQuery === null &&
450
- (typeof this.filterMethod === 'function' || typeof this.remoteMethod === 'function')
451
- ) {
452
- this.previousQuery = val;
453
- return;
454
- }
455
- this.previousQuery = val;
456
- this.$nextTick(() => {
457
- if (this.visible) this.broadcast('ElSelectDropdown', 'updatePopper');
458
- });
459
- this.hoverIndex = -1;
460
- if (this.multiple && this.filterable) {
461
- const length = this.$refs.input.value.length * 15 + 20;
462
- this.inputLength = this.collapseTags ? Math.min(50, length) : length;
463
- this.managePlaceholder();
464
- this.resetInputHeight();
465
- }
466
- if (this.remote && typeof this.remoteMethod === 'function') {
467
- this.hoverIndex = -1;
468
- this.remoteMethod(val);
469
- } else if (typeof this.filterMethod === 'function') {
470
- this.filterMethod(val);
471
- this.broadcast('ElOptionGroup', 'queryChange');
472
- } else {
473
- this.filteredOptionsCount = this.optionsCount;
474
- this.broadcast('ElOption', 'queryChange', val);
475
- this.broadcast('ElOptionGroup', 'queryChange');
476
- }
477
- if (this.defaultFirstOption && (this.filterable || this.remote) && this.filteredOptionsCount) {
478
- this.checkDefaultFirstOption();
479
- }
480
- },
481
-
482
- scrollToOption(option) {
483
- const target = Array.isArray(option) && option[0] ? option[0].$el : option.$el;
484
- if (this.$refs.popper && target) {
485
- const menu = this.$refs.popper.$el.querySelector('.el-select-dropdown__wrap');
486
- scrollIntoView(menu, target);
487
- }
488
- this.$refs.scrollbar && this.$refs.scrollbar.handleScroll();
489
- },
490
-
491
- handleMenuEnter() {
492
- this.$nextTick(() => this.scrollToOption(this.selected));
493
- },
494
-
495
- emitChange(val) {
496
- if (!valueEquals(this.value, val)) {
497
- this.$emit('change', val);
498
- }
499
- },
500
-
501
- getOption(value) {
502
- let option;
503
- const isObject = Object.prototype.toString.call(value).toLowerCase() === '[object object]';
504
- const isNull = Object.prototype.toString.call(value).toLowerCase() === '[object null]';
505
-
506
- for (let i = this.cachedOptions.length - 1; i >= 0; i--) {
507
- const cachedOption = this.cachedOptions[i];
508
- const isEqual = isObject
509
- ? getValueByPath(cachedOption.value, this.valueKey) === getValueByPath(value, this.valueKey)
510
- : cachedOption.value === value;
511
- if (isEqual) {
512
- option = cachedOption;
513
- break;
514
- }
515
- }
516
- if (option) return option;
517
- const label = (!isObject && !isNull)
518
- ? value : '';
519
- let newOption = {
520
- value: value,
521
- currentLabel: label
522
- };
523
- if (this.multiple) {
524
- newOption.hitState = false;
525
- }
526
- return newOption;
527
- },
528
-
529
- setSelected() {
530
- if (!this.multiple) {
531
- let option = this.getOption(this.value);
532
- if (option.created) {
533
- this.createdLabel = option.currentLabel;
534
- this.createdSelected = true;
535
- } else {
536
- this.createdSelected = false;
537
- }
538
- this.selectedLabel = option.currentLabel;
539
- this.selected = option;
540
- if (this.filterable) this.query = this.selectedLabel;
541
- return;
542
- }
543
- let result = [];
544
- if (Array.isArray(this.value)) {
545
- this.value.forEach(value => {
546
- result.push(this.getOption(value));
547
- });
548
- }
549
- this.selected = result;
550
- this.$nextTick(() => {
551
- this.resetInputHeight();
552
- });
553
- },
554
-
555
- handleFocus(event) {
556
- if (!this.softFocus) {
557
- if (this.automaticDropdown || this.filterable) {
558
- this.visible = true;
559
- this.menuVisibleOnFocus = true;
560
- }
561
- this.$emit('focus', event);
562
- } else {
563
- this.softFocus = false;
564
- }
565
- },
566
-
567
- blur() {
568
- this.visible = false;
569
- this.$refs.reference.blur();
570
- },
571
-
572
- handleBlur(event) {
573
- setTimeout(() => {
574
- if (this.isSilentBlur) {
575
- this.isSilentBlur = false;
576
- } else {
577
- this.$emit('blur', event);
578
- }
579
- }, 50);
580
- this.softFocus = false;
581
- },
582
-
583
- handleClearClick(event) {
584
- this.deleteSelected(event);
585
- },
586
-
587
- doDestroy() {
588
- this.$refs.popper && this.$refs.popper.doDestroy();
589
- },
590
-
591
- handleClose() {
592
- this.visible = false;
593
- },
594
-
595
- toggleLastOptionHitState(hit) {
596
- if (!Array.isArray(this.selected)) return;
597
- const option = this.selected[this.selected.length - 1];
598
- if (!option) return;
599
-
600
- if (hit === true || hit === false) {
601
- option.hitState = hit;
602
- return hit;
603
- }
604
-
605
- option.hitState = !option.hitState;
606
- return option.hitState;
607
- },
608
-
609
- deletePrevTag(e) {
610
- if (e.target.value.length <= 0 && !this.toggleLastOptionHitState()) {
611
- const value = this.value.slice();
612
- value.pop();
613
- this.$emit('input', value);
614
- this.emitChange(value);
615
- }
616
- },
617
-
618
- managePlaceholder() {
619
- if (this.currentPlaceholder !== '') {
620
- this.currentPlaceholder = this.$refs.input.value ? '' : this.cachedPlaceHolder;
621
- }
622
- },
623
-
624
- resetInputState(e) {
625
- if (e.keyCode !== 8) this.toggleLastOptionHitState(false);
626
- this.inputLength = this.$refs.input.value.length * 15 + 20;
627
- this.resetInputHeight();
628
- },
629
-
630
- resetInputHeight() {
631
- if (this.collapseTags && !this.filterable) return;
632
- this.$nextTick(() => {
633
- if (!this.$refs.reference) return;
634
- let inputChildNodes = this.$refs.reference.$el.childNodes;
635
- let input = [].filter.call(inputChildNodes, item => item.tagName === 'INPUT')[0];
636
- const tags = this.$refs.tags;
637
- const sizeInMap = this.initialInputHeight || 40;
638
- input.style.height = this.selected.length === 0
639
- ? sizeInMap + 'px'
640
- : Math.max(
641
- tags ? (tags.clientHeight + (tags.clientHeight > sizeInMap ? 6 : 0)) : 0,
642
- sizeInMap
643
- ) + 'px';
644
- if (this.visible && this.emptyText !== false) {
645
- this.broadcast('ElSelectDropdown', 'updatePopper');
646
- }
647
- });
648
- },
649
-
650
- resetHoverIndex() {
651
- setTimeout(() => {
652
- if (!this.multiple) {
653
- this.hoverIndex = this.options.indexOf(this.selected);
654
- } else {
655
- if (this.selected.length > 0) {
656
- this.hoverIndex = Math.min.apply(null, this.selected.map(item => this.options.indexOf(item)));
657
- } else {
658
- this.hoverIndex = -1;
659
- }
660
- }
661
- }, 300);
662
- },
663
-
664
- handleOptionSelect(option, byClick) {
665
- if (this.multiple) {
666
- const value = this.value.slice();
667
- const optionIndex = this.getValueIndex(value, option.value);
668
- if (optionIndex > -1) {
669
- value.splice(optionIndex, 1);
670
- } else if (this.multipleLimit <= 0 || value.length < this.multipleLimit) {
671
- value.push(option.value);
672
- }
673
- this.$emit('input', value);
674
- this.emitChange(value);
675
- if (option.created) {
676
- this.query = '';
677
- this.handleQueryChange('');
678
- this.inputLength = 20;
679
- }
680
- if (this.filterable) this.$refs.input.focus();
681
- } else {
682
- this.$emit('input', option.value);
683
- this.emitChange(option.value);
684
- this.visible = false;
685
- }
686
- this.isSilentBlur = byClick;
687
- this.setSoftFocus();
688
- if (this.visible) return;
689
- this.$nextTick(() => {
690
- this.scrollToOption(option);
691
- });
692
- },
693
-
694
- setSoftFocus() {
695
- this.softFocus = true;
696
- const input = this.$refs.input || this.$refs.reference;
697
- if (input) {
698
- input.focus();
699
- }
700
- },
701
-
702
- getValueIndex(arr = [], value) {
703
- const isObject = Object.prototype.toString.call(value).toLowerCase() === '[object object]';
704
- if (!isObject) {
705
- return arr.indexOf(value);
706
- } else {
707
- const valueKey = this.valueKey;
708
- let index = -1;
709
- arr.some((item, i) => {
710
- if (getValueByPath(item, valueKey) === getValueByPath(value, valueKey)) {
711
- index = i;
712
- return true;
713
- }
714
- return false;
715
- });
716
- return index;
717
- }
718
- },
719
-
720
- toggleMenu() {
721
- if (!this.selectDisabled) {
722
- if (this.menuVisibleOnFocus) {
723
- this.menuVisibleOnFocus = false;
724
- } else {
725
- this.visible = !this.visible;
726
- }
727
- if (this.visible) {
728
- (this.$refs.input || this.$refs.reference).focus();
729
- }
730
- }
731
- },
732
-
733
- selectOption() {
734
- if (!this.visible) {
735
- this.toggleMenu();
736
- } else {
737
- if (this.options[this.hoverIndex]) {
738
- this.handleOptionSelect(this.options[this.hoverIndex]);
739
- }
740
- }
741
- },
742
-
743
- deleteSelected(event) {
744
- event.stopPropagation();
745
- const value = this.multiple ? [] : '';
746
- this.$emit('input', value);
747
- this.emitChange(value);
748
- this.visible = false;
749
- this.$emit('clear');
750
- },
751
-
752
- deleteTag(event, tag) {
753
- let index = this.selected.indexOf(tag);
754
- if (index > -1 && !this.selectDisabled) {
755
- const value = this.value.slice();
756
- value.splice(index, 1);
757
- this.$emit('input', value);
758
- this.emitChange(value);
759
- this.$emit('remove-tag', tag.value);
760
- }
761
- event.stopPropagation();
762
- },
763
-
764
- onInputChange() {
765
- if (this.filterable && this.query !== this.selectedLabel) {
766
- this.query = this.selectedLabel;
767
- this.handleQueryChange(this.query);
768
- }
769
- },
770
-
771
- onOptionDestroy(index) {
772
- if (index > -1) {
773
- this.optionsCount--;
774
- this.filteredOptionsCount--;
775
- this.options.splice(index, 1);
776
- }
777
- },
778
-
779
- resetInputWidth() {
780
- this.inputWidth = this.$refs.reference.$el.getBoundingClientRect().width;
781
- },
782
-
783
- handleResize() {
784
- this.resetInputWidth();
785
- if (this.multiple) this.resetInputHeight();
786
- },
787
-
788
- checkDefaultFirstOption() {
789
- this.hoverIndex = -1;
790
- // highlight the created option
791
- let hasCreated = false;
792
- for (let i = this.options.length - 1; i >= 0; i--) {
793
- if (this.options[i].created) {
794
- hasCreated = true;
795
- this.hoverIndex = i;
796
- break;
797
- }
798
- }
799
- if (hasCreated) return;
800
- for (let i = 0; i !== this.options.length; ++i) {
801
- const option = this.options[i];
802
- if (this.query) {
803
- // highlight first options that passes the filter
804
- if (!option.disabled && !option.groupDisabled && option.visible) {
805
- this.hoverIndex = i;
806
- break;
807
- }
808
- } else {
809
- // highlight currently selected option
810
- if (option.itemSelected) {
811
- this.hoverIndex = i;
812
- break;
813
- }
814
- }
815
- }
816
- },
817
-
818
- getValueKey(item) {
819
- if (Object.prototype.toString.call(item.value).toLowerCase() !== '[object object]') {
820
- return item.value;
821
- } else {
822
- return getValueByPath(item.value, this.valueKey);
823
- }
824
- }
825
- },
826
-
827
- created() {
828
- this.cachedPlaceHolder = this.currentPlaceholder = this.placeholder;
829
- if (this.multiple && !Array.isArray(this.value)) {
830
- this.$emit('input', []);
831
- }
832
- if (!this.multiple && Array.isArray(this.value)) {
833
- this.$emit('input', '');
834
- }
835
-
836
- this.debouncedOnInputChange = debounce(this.debounce, () => {
837
- this.onInputChange();
838
- });
839
-
840
- this.debouncedQueryChange = debounce(this.debounce, (e) => {
841
- this.handleQueryChange(e.target.value);
842
- });
843
-
844
- this.$on('handleOptionClick', this.handleOptionSelect);
845
- this.$on('setSelected', this.setSelected);
846
- },
847
-
848
- mounted() {
849
- if (this.multiple && Array.isArray(this.value) && this.value.length > 0) {
850
- this.currentPlaceholder = '';
851
- }
852
- addResizeListener(this.$el, this.handleResize);
853
-
854
- const reference = this.$refs.reference;
855
- if (reference && reference.$el) {
856
- const sizeMap = {
857
- medium: 36,
858
- small: 32,
859
- mini: 28
860
- };
861
- this.initialInputHeight = reference.$el.getBoundingClientRect().height || sizeMap[this.selectSize];
862
- }
863
- if (this.remote && this.multiple) {
864
- this.resetInputHeight();
865
- }
866
- this.$nextTick(() => {
867
- if (reference && reference.$el) {
868
- this.inputWidth = reference.$el.getBoundingClientRect().width;
869
- }
870
- });
871
- this.setSelected();
872
- },
873
-
874
- beforeDestroy() {
875
- if (this.$el && this.handleResize) removeResizeListener(this.$el, this.handleResize);
876
- }
877
- };
878
- </script>
1
+ <template>
2
+ <div
3
+ class="el-select"
4
+ :class="[selectSize ? 'el-select--' + selectSize : '']"
5
+ @click.stop="toggleMenu"
6
+ v-clickoutside="handleClose">
7
+ <div
8
+ class="el-select__tags"
9
+ v-if="multiple"
10
+ ref="tags"
11
+ :style="{ 'max-width': inputWidth - 32 + 'px', width: '100%' }">
12
+ <span v-if="collapseTags && selected.length">
13
+ <el-tag
14
+ :closable="!selectDisabled"
15
+ :size="collapseTagSize"
16
+ :hit="selected[0].hitState"
17
+ type="info"
18
+ @close="deleteTag($event, selected[0])"
19
+ disable-transitions>
20
+ <span class="el-select__tags-text">{{ selected[0].currentLabel }}</span>
21
+ </el-tag>
22
+ <el-tag
23
+ v-if="selected.length > 1"
24
+ :closable="false"
25
+ :size="collapseTagSize"
26
+ type="info"
27
+ disable-transitions>
28
+ <span class="el-select__tags-text">+ {{ selected.length - 1 }}</span>
29
+ </el-tag>
30
+ </span>
31
+ <transition-group @after-leave="resetInputHeight" v-if="!collapseTags">
32
+ <el-tag
33
+ v-for="item in selected"
34
+ :key="getValueKey(item)"
35
+ :closable="!selectDisabled"
36
+ :size="collapseTagSize"
37
+ :hit="item.hitState"
38
+ type="info"
39
+ @close="deleteTag($event, item)"
40
+ disable-transitions>
41
+ <span class="el-select__tags-text">{{ item.currentLabel }}</span>
42
+ </el-tag>
43
+ </transition-group>
44
+
45
+ <input
46
+ type="text"
47
+ class="el-select__input"
48
+ :class="[selectSize ? `is-${ selectSize }` : '']"
49
+ :disabled="selectDisabled"
50
+ :autocomplete="autoComplete || autocomplete"
51
+ @focus="handleFocus"
52
+ @blur="softFocus = false"
53
+ @click.stop
54
+ @keyup="managePlaceholder"
55
+ @keydown="resetInputState"
56
+ @keydown.down.prevent="navigateOptions('next')"
57
+ @keydown.up.prevent="navigateOptions('prev')"
58
+ @keydown.enter.prevent="selectOption"
59
+ @keydown.esc.stop.prevent="visible = false"
60
+ @keydown.delete="deletePrevTag"
61
+ @compositionstart="handleComposition"
62
+ @compositionupdate="handleComposition"
63
+ @compositionend="handleComposition"
64
+ v-model="query"
65
+ @input="debouncedQueryChange"
66
+ v-if="filterable"
67
+ :style="{ 'flex-grow': '1', width: inputLength / (inputWidth - 32) + '%', 'max-width': inputWidth - 42 + 'px' }"
68
+ ref="input">
69
+ </div>
70
+ <el-input
71
+ ref="reference"
72
+ v-model="selectedLabel"
73
+ type="text"
74
+ :placeholder="currentPlaceholder"
75
+ :name="name"
76
+ :id="id"
77
+ :autocomplete="autoComplete || autocomplete"
78
+ :size="selectSize"
79
+ :disabled="selectDisabled"
80
+ :readonly="readonly"
81
+ :validate-event="false"
82
+ :class="{ 'is-focus': visible }"
83
+ @focus="handleFocus"
84
+ @blur="handleBlur"
85
+ @keyup.native="debouncedOnInputChange"
86
+ @keydown.native.down.stop.prevent="navigateOptions('next')"
87
+ @keydown.native.up.stop.prevent="navigateOptions('prev')"
88
+ @keydown.native.enter.prevent="selectOption"
89
+ @keydown.native.esc.stop.prevent="visible = false"
90
+ @keydown.native.tab="visible = false"
91
+ @paste.native="debouncedOnInputChange"
92
+ @mouseenter.native="inputHovering = true"
93
+ @mouseleave.native="inputHovering = false">
94
+ <template slot="prefix" v-if="$slots.prefix">
95
+ <slot name="prefix"></slot>
96
+ </template>
97
+ <template slot="suffix">
98
+ <i v-show="!showClose" :class="['el-select__caret', 'el-input__icon', 'el-icon-' + iconClass]"></i>
99
+ <i v-if="showClose" class="el-select__caret el-input__icon el-icon-circle-close" @click="handleClearClick"></i>
100
+ </template>
101
+ </el-input>
102
+ <transition
103
+ name="el-zoom-in-top"
104
+ @before-enter="handleMenuEnter"
105
+ @after-leave="doDestroy">
106
+ <el-select-menu
107
+ ref="popper"
108
+ :append-to-body="popperAppendToBody"
109
+ v-show="visible && emptyText !== false">
110
+ <el-scrollbar
111
+ tag="ul"
112
+ wrap-class="el-select-dropdown__wrap"
113
+ view-class="el-select-dropdown__list"
114
+ ref="scrollbar"
115
+ :class="{ 'is-empty': !allowCreate && query && filteredOptionsCount === 0 }"
116
+ v-show="options.length > 0 && !loading">
117
+ <el-option
118
+ :value="query"
119
+ created
120
+ v-if="showNewOption">
121
+ </el-option>
122
+ <slot></slot>
123
+ </el-scrollbar>
124
+ <p
125
+ class="el-select-dropdown__empty"
126
+ v-if="emptyText &&
127
+ (!allowCreate || loading || (allowCreate && options.length === 0 ))">
128
+ {{ emptyText }}
129
+ </p>
130
+ </el-select-menu>
131
+ </transition>
132
+ </div>
133
+ </template>
134
+
135
+ <script type="text/babel">
136
+ import Emitter from '@penggy/element-ui/src/mixins/emitter';
137
+ import Focus from '@penggy/element-ui/src/mixins/focus';
138
+ import Locale from '@penggy/element-ui/src/mixins/locale';
139
+ import ElInput from '@penggy/element-ui/packages/input';
140
+ import ElSelectMenu from './select-dropdown.vue';
141
+ import ElOption from './option.vue';
142
+ import ElTag from '@penggy/element-ui/packages/tag';
143
+ import ElScrollbar from '@penggy/element-ui/packages/scrollbar';
144
+ import debounce from 'throttle-debounce/debounce';
145
+ import Clickoutside from '@penggy/element-ui/src/utils/clickoutside';
146
+ import { addResizeListener, removeResizeListener } from '@penggy/element-ui/src/utils/resize-event';
147
+ import { t } from '@penggy/element-ui/src/locale';
148
+ import scrollIntoView from '@penggy/element-ui/src/utils/scroll-into-view';
149
+ import { getValueByPath } from '@penggy/element-ui/src/utils/util';
150
+ import { valueEquals, isIE, isEdge } from '@penggy/element-ui/src/utils/util';
151
+ import NavigationMixin from './navigation-mixin';
152
+ import { isKorean } from '@penggy/element-ui/src/utils/shared';
153
+
154
+ export default {
155
+ mixins: [Emitter, Locale, Focus('reference'), NavigationMixin],
156
+
157
+ name: 'ElSelect',
158
+
159
+ componentName: 'ElSelect',
160
+
161
+ inject: {
162
+ elForm: {
163
+ default: ''
164
+ },
165
+
166
+ elFormItem: {
167
+ default: ''
168
+ }
169
+ },
170
+
171
+ provide() {
172
+ return {
173
+ 'select': this
174
+ };
175
+ },
176
+
177
+ computed: {
178
+ _elFormItemSize() {
179
+ return (this.elFormItem || {}).elFormItemSize;
180
+ },
181
+
182
+ readonly() {
183
+ return !this.filterable || this.multiple || (!isIE() && !isEdge() && !this.visible);
184
+ },
185
+
186
+ showClose() {
187
+ let hasValue = this.multiple
188
+ ? Array.isArray(this.value) && this.value.length > 0
189
+ : this.value !== undefined && this.value !== null && this.value !== '';
190
+ let criteria = this.clearable &&
191
+ !this.selectDisabled &&
192
+ this.inputHovering &&
193
+ hasValue;
194
+ return criteria;
195
+ },
196
+
197
+ iconClass() {
198
+ return this.remote && this.filterable ? '' : (this.visible ? 'arrow-up is-reverse' : 'arrow-up');
199
+ },
200
+
201
+ debounce() {
202
+ return this.remote ? 300 : 0;
203
+ },
204
+
205
+ emptyText() {
206
+ if (this.loading) {
207
+ return this.loadingText || this.t('el.select.loading');
208
+ } else {
209
+ if (this.remote && this.query === '' && this.options.length === 0) return false;
210
+ if (this.filterable && this.query && this.options.length > 0 && this.filteredOptionsCount === 0) {
211
+ return this.noMatchText || this.t('el.select.noMatch');
212
+ }
213
+ if (this.options.length === 0) {
214
+ return this.noDataText || this.t('el.select.noData');
215
+ }
216
+ }
217
+ return null;
218
+ },
219
+
220
+ showNewOption() {
221
+ let hasExistingOption = this.options.filter(option => !option.created)
222
+ .some(option => option.currentLabel === this.query);
223
+ return this.filterable && this.allowCreate && this.query !== '' && !hasExistingOption;
224
+ },
225
+
226
+ selectSize() {
227
+ return this.size || this._elFormItemSize || (this.$ELEMENT || {}).size;
228
+ },
229
+
230
+ selectDisabled() {
231
+ return this.disabled || (this.elForm || {}).disabled;
232
+ },
233
+
234
+ collapseTagSize() {
235
+ return ['small', 'mini'].indexOf(this.selectSize) > -1
236
+ ? 'mini'
237
+ : 'small';
238
+ }
239
+ },
240
+
241
+ components: {
242
+ ElInput,
243
+ ElSelectMenu,
244
+ ElOption,
245
+ ElTag,
246
+ ElScrollbar
247
+ },
248
+
249
+ directives: { Clickoutside },
250
+
251
+ props: {
252
+ name: String,
253
+ id: String,
254
+ value: {
255
+ required: true
256
+ },
257
+ autocomplete: {
258
+ type: String,
259
+ default: 'off'
260
+ },
261
+ /** @Deprecated in next major version */
262
+ autoComplete: {
263
+ type: String,
264
+ validator(val) {
265
+ process.env.NODE_ENV !== 'production' &&
266
+ console.warn('[Element Warn][Select]\'auto-complete\' property will be deprecated in next major version. please use \'autocomplete\' instead.');
267
+ return true;
268
+ }
269
+ },
270
+ automaticDropdown: Boolean,
271
+ size: String,
272
+ disabled: Boolean,
273
+ clearable: Boolean,
274
+ filterable: Boolean,
275
+ allowCreate: Boolean,
276
+ loading: Boolean,
277
+ popperClass: String,
278
+ remote: Boolean,
279
+ loadingText: String,
280
+ noMatchText: String,
281
+ noDataText: String,
282
+ remoteMethod: Function,
283
+ filterMethod: Function,
284
+ multiple: Boolean,
285
+ multipleLimit: {
286
+ type: Number,
287
+ default: 0
288
+ },
289
+ placeholder: {
290
+ type: String,
291
+ default() {
292
+ return t('el.select.placeholder');
293
+ }
294
+ },
295
+ defaultFirstOption: Boolean,
296
+ reserveKeyword: Boolean,
297
+ valueKey: {
298
+ type: String,
299
+ default: 'value'
300
+ },
301
+ collapseTags: Boolean,
302
+ popperAppendToBody: {
303
+ type: Boolean,
304
+ default: true
305
+ }
306
+ },
307
+
308
+ data() {
309
+ return {
310
+ options: [],
311
+ cachedOptions: [],
312
+ createdLabel: null,
313
+ createdSelected: false,
314
+ selected: this.multiple ? [] : {},
315
+ inputLength: 20,
316
+ inputWidth: 0,
317
+ initialInputHeight: 0,
318
+ cachedPlaceHolder: '',
319
+ optionsCount: 0,
320
+ filteredOptionsCount: 0,
321
+ visible: false,
322
+ softFocus: false,
323
+ selectedLabel: '',
324
+ hoverIndex: -1,
325
+ query: '',
326
+ previousQuery: null,
327
+ inputHovering: false,
328
+ currentPlaceholder: '',
329
+ menuVisibleOnFocus: false,
330
+ isOnComposition: false,
331
+ isSilentBlur: false
332
+ };
333
+ },
334
+
335
+ watch: {
336
+ selectDisabled() {
337
+ this.$nextTick(() => {
338
+ this.resetInputHeight();
339
+ });
340
+ },
341
+
342
+ placeholder(val) {
343
+ this.cachedPlaceHolder = this.currentPlaceholder = val;
344
+ },
345
+
346
+ value(val, oldVal) {
347
+ if (this.multiple) {
348
+ this.resetInputHeight();
349
+ if (val.length > 0 || (this.$refs.input && this.query !== '')) {
350
+ this.currentPlaceholder = '';
351
+ } else {
352
+ this.currentPlaceholder = this.cachedPlaceHolder;
353
+ }
354
+ if (this.filterable && !this.reserveKeyword) {
355
+ this.query = '';
356
+ this.handleQueryChange(this.query);
357
+ }
358
+ }
359
+ this.setSelected();
360
+ if (this.filterable && !this.multiple) {
361
+ this.inputLength = 20;
362
+ }
363
+ if (!valueEquals(val, oldVal)) {
364
+ this.dispatch('ElFormItem', 'el.form.change', val);
365
+ }
366
+ },
367
+
368
+ visible(val) {
369
+ if (!val) {
370
+ this.broadcast('ElSelectDropdown', 'destroyPopper');
371
+ if (this.$refs.input) {
372
+ this.$refs.input.blur();
373
+ }
374
+ this.query = '';
375
+ this.previousQuery = null;
376
+ this.selectedLabel = '';
377
+ this.inputLength = 20;
378
+ this.menuVisibleOnFocus = false;
379
+ this.resetHoverIndex();
380
+ this.$nextTick(() => {
381
+ if (this.$refs.input &&
382
+ this.$refs.input.value === '' &&
383
+ this.selected.length === 0) {
384
+ this.currentPlaceholder = this.cachedPlaceHolder;
385
+ }
386
+ });
387
+ if (!this.multiple) {
388
+ if (this.selected) {
389
+ if (this.filterable && this.allowCreate &&
390
+ this.createdSelected && this.createdLabel) {
391
+ this.selectedLabel = this.createdLabel;
392
+ } else {
393
+ this.selectedLabel = this.selected.currentLabel;
394
+ }
395
+ if (this.filterable) this.query = this.selectedLabel;
396
+ }
397
+ }
398
+ } else {
399
+ this.broadcast('ElSelectDropdown', 'updatePopper');
400
+ if (this.filterable) {
401
+ this.query = this.remote ? '' : this.selectedLabel;
402
+ this.handleQueryChange(this.query);
403
+ if (this.multiple) {
404
+ this.$refs.input.focus();
405
+ } else {
406
+ if (!this.remote) {
407
+ this.broadcast('ElOption', 'queryChange', '');
408
+ this.broadcast('ElOptionGroup', 'queryChange');
409
+ }
410
+ this.broadcast('ElInput', 'inputSelect');
411
+ }
412
+ }
413
+ }
414
+ this.$emit('visible-change', val);
415
+ },
416
+
417
+ options() {
418
+ if (this.$isServer) return;
419
+ this.$nextTick(() => {
420
+ this.broadcast('ElSelectDropdown', 'updatePopper');
421
+ });
422
+ if (this.multiple) {
423
+ this.resetInputHeight();
424
+ }
425
+ let inputs = this.$el.querySelectorAll('input');
426
+ if ([].indexOf.call(inputs, document.activeElement) === -1) {
427
+ this.setSelected();
428
+ }
429
+ if (this.defaultFirstOption && (this.filterable || this.remote) && this.filteredOptionsCount) {
430
+ this.checkDefaultFirstOption();
431
+ }
432
+ }
433
+ },
434
+
435
+ methods: {
436
+ handleComposition(event) {
437
+ const text = event.target.value;
438
+ if (event.type === 'compositionend') {
439
+ this.isOnComposition = false;
440
+ this.handleQueryChange(text);
441
+ } else {
442
+ const lastCharacter = text[text.length - 1] || '';
443
+ this.isOnComposition = !isKorean(lastCharacter);
444
+ }
445
+ },
446
+ handleQueryChange(val) {
447
+ if (this.previousQuery === val || this.isOnComposition) return;
448
+ if (
449
+ this.previousQuery === null &&
450
+ (typeof this.filterMethod === 'function' || typeof this.remoteMethod === 'function')
451
+ ) {
452
+ this.previousQuery = val;
453
+ return;
454
+ }
455
+ this.previousQuery = val;
456
+ this.$nextTick(() => {
457
+ if (this.visible) this.broadcast('ElSelectDropdown', 'updatePopper');
458
+ });
459
+ this.hoverIndex = -1;
460
+ if (this.multiple && this.filterable) {
461
+ const length = this.$refs.input.value.length * 15 + 20;
462
+ this.inputLength = this.collapseTags ? Math.min(50, length) : length;
463
+ this.managePlaceholder();
464
+ this.resetInputHeight();
465
+ }
466
+ if (this.remote && typeof this.remoteMethod === 'function') {
467
+ this.hoverIndex = -1;
468
+ this.remoteMethod(val);
469
+ } else if (typeof this.filterMethod === 'function') {
470
+ this.filterMethod(val);
471
+ this.broadcast('ElOptionGroup', 'queryChange');
472
+ } else {
473
+ this.filteredOptionsCount = this.optionsCount;
474
+ this.broadcast('ElOption', 'queryChange', val);
475
+ this.broadcast('ElOptionGroup', 'queryChange');
476
+ }
477
+ if (this.defaultFirstOption && (this.filterable || this.remote) && this.filteredOptionsCount) {
478
+ this.checkDefaultFirstOption();
479
+ }
480
+ },
481
+
482
+ scrollToOption(option) {
483
+ const target = Array.isArray(option) && option[0] ? option[0].$el : option.$el;
484
+ if (this.$refs.popper && target) {
485
+ const menu = this.$refs.popper.$el.querySelector('.el-select-dropdown__wrap');
486
+ scrollIntoView(menu, target);
487
+ }
488
+ this.$refs.scrollbar && this.$refs.scrollbar.handleScroll();
489
+ },
490
+
491
+ handleMenuEnter() {
492
+ this.$nextTick(() => this.scrollToOption(this.selected));
493
+ },
494
+
495
+ emitChange(val) {
496
+ if (!valueEquals(this.value, val)) {
497
+ this.$emit('change', val);
498
+ }
499
+ },
500
+
501
+ getOption(value) {
502
+ let option;
503
+ const isObject = Object.prototype.toString.call(value).toLowerCase() === '[object object]';
504
+ const isNull = Object.prototype.toString.call(value).toLowerCase() === '[object null]';
505
+
506
+ for (let i = this.cachedOptions.length - 1; i >= 0; i--) {
507
+ const cachedOption = this.cachedOptions[i];
508
+ const isEqual = isObject
509
+ ? getValueByPath(cachedOption.value, this.valueKey) === getValueByPath(value, this.valueKey)
510
+ : cachedOption.value === value;
511
+ if (isEqual) {
512
+ option = cachedOption;
513
+ break;
514
+ }
515
+ }
516
+ if (option) return option;
517
+ const label = (!isObject && !isNull)
518
+ ? value : '';
519
+ let newOption = {
520
+ value: value,
521
+ currentLabel: label
522
+ };
523
+ if (this.multiple) {
524
+ newOption.hitState = false;
525
+ }
526
+ return newOption;
527
+ },
528
+
529
+ setSelected() {
530
+ if (!this.multiple) {
531
+ let option = this.getOption(this.value);
532
+ if (option.created) {
533
+ this.createdLabel = option.currentLabel;
534
+ this.createdSelected = true;
535
+ } else {
536
+ this.createdSelected = false;
537
+ }
538
+ this.selectedLabel = option.currentLabel;
539
+ this.selected = option;
540
+ if (this.filterable) this.query = this.selectedLabel;
541
+ return;
542
+ }
543
+ let result = [];
544
+ if (Array.isArray(this.value)) {
545
+ this.value.forEach(value => {
546
+ result.push(this.getOption(value));
547
+ });
548
+ }
549
+ this.selected = result;
550
+ this.$nextTick(() => {
551
+ this.resetInputHeight();
552
+ });
553
+ },
554
+
555
+ handleFocus(event) {
556
+ if (!this.softFocus) {
557
+ if (this.automaticDropdown || this.filterable) {
558
+ this.visible = true;
559
+ this.menuVisibleOnFocus = true;
560
+ }
561
+ this.$emit('focus', event);
562
+ } else {
563
+ this.softFocus = false;
564
+ }
565
+ },
566
+
567
+ blur() {
568
+ this.visible = false;
569
+ this.$refs.reference.blur();
570
+ },
571
+
572
+ handleBlur(event) {
573
+ setTimeout(() => {
574
+ if (this.isSilentBlur) {
575
+ this.isSilentBlur = false;
576
+ } else {
577
+ this.$emit('blur', event);
578
+ }
579
+ }, 50);
580
+ this.softFocus = false;
581
+ },
582
+
583
+ handleClearClick(event) {
584
+ this.deleteSelected(event);
585
+ },
586
+
587
+ doDestroy() {
588
+ this.$refs.popper && this.$refs.popper.doDestroy();
589
+ },
590
+
591
+ handleClose() {
592
+ this.visible = false;
593
+ },
594
+
595
+ toggleLastOptionHitState(hit) {
596
+ if (!Array.isArray(this.selected)) return;
597
+ const option = this.selected[this.selected.length - 1];
598
+ if (!option) return;
599
+
600
+ if (hit === true || hit === false) {
601
+ option.hitState = hit;
602
+ return hit;
603
+ }
604
+
605
+ option.hitState = !option.hitState;
606
+ return option.hitState;
607
+ },
608
+
609
+ deletePrevTag(e) {
610
+ if (e.target.value.length <= 0 && !this.toggleLastOptionHitState()) {
611
+ const value = this.value.slice();
612
+ value.pop();
613
+ this.$emit('input', value);
614
+ this.emitChange(value);
615
+ }
616
+ },
617
+
618
+ managePlaceholder() {
619
+ if (this.currentPlaceholder !== '') {
620
+ this.currentPlaceholder = this.$refs.input.value ? '' : this.cachedPlaceHolder;
621
+ }
622
+ },
623
+
624
+ resetInputState(e) {
625
+ if (e.keyCode !== 8) this.toggleLastOptionHitState(false);
626
+ this.inputLength = this.$refs.input.value.length * 15 + 20;
627
+ this.resetInputHeight();
628
+ },
629
+
630
+ resetInputHeight() {
631
+ if (this.collapseTags && !this.filterable) return;
632
+ this.$nextTick(() => {
633
+ if (!this.$refs.reference) return;
634
+ let inputChildNodes = this.$refs.reference.$el.childNodes;
635
+ let input = [].filter.call(inputChildNodes, item => item.tagName === 'INPUT')[0];
636
+ const tags = this.$refs.tags;
637
+ const sizeInMap = this.initialInputHeight || 40;
638
+ input.style.height = this.selected.length === 0
639
+ ? sizeInMap + 'px'
640
+ : Math.max(
641
+ tags ? (tags.clientHeight + (tags.clientHeight > sizeInMap ? 6 : 0)) : 0,
642
+ sizeInMap
643
+ ) + 'px';
644
+ if (this.visible && this.emptyText !== false) {
645
+ this.broadcast('ElSelectDropdown', 'updatePopper');
646
+ }
647
+ });
648
+ },
649
+
650
+ resetHoverIndex() {
651
+ setTimeout(() => {
652
+ if (!this.multiple) {
653
+ this.hoverIndex = this.options.indexOf(this.selected);
654
+ } else {
655
+ if (this.selected.length > 0) {
656
+ this.hoverIndex = Math.min.apply(null, this.selected.map(item => this.options.indexOf(item)));
657
+ } else {
658
+ this.hoverIndex = -1;
659
+ }
660
+ }
661
+ }, 300);
662
+ },
663
+
664
+ handleOptionSelect(option, byClick) {
665
+ if (this.multiple) {
666
+ const value = this.value.slice();
667
+ const optionIndex = this.getValueIndex(value, option.value);
668
+ if (optionIndex > -1) {
669
+ value.splice(optionIndex, 1);
670
+ } else if (this.multipleLimit <= 0 || value.length < this.multipleLimit) {
671
+ value.push(option.value);
672
+ }
673
+ this.$emit('input', value);
674
+ this.emitChange(value);
675
+ if (option.created) {
676
+ this.query = '';
677
+ this.handleQueryChange('');
678
+ this.inputLength = 20;
679
+ }
680
+ if (this.filterable) this.$refs.input.focus();
681
+ } else {
682
+ this.$emit('input', option.value);
683
+ this.emitChange(option.value);
684
+ this.visible = false;
685
+ }
686
+ this.isSilentBlur = byClick;
687
+ this.setSoftFocus();
688
+ if (this.visible) return;
689
+ this.$nextTick(() => {
690
+ this.scrollToOption(option);
691
+ });
692
+ },
693
+
694
+ setSoftFocus() {
695
+ this.softFocus = true;
696
+ const input = this.$refs.input || this.$refs.reference;
697
+ if (input) {
698
+ input.focus();
699
+ }
700
+ },
701
+
702
+ getValueIndex(arr = [], value) {
703
+ const isObject = Object.prototype.toString.call(value).toLowerCase() === '[object object]';
704
+ if (!isObject) {
705
+ return arr.indexOf(value);
706
+ } else {
707
+ const valueKey = this.valueKey;
708
+ let index = -1;
709
+ arr.some((item, i) => {
710
+ if (getValueByPath(item, valueKey) === getValueByPath(value, valueKey)) {
711
+ index = i;
712
+ return true;
713
+ }
714
+ return false;
715
+ });
716
+ return index;
717
+ }
718
+ },
719
+
720
+ toggleMenu() {
721
+ if (!this.selectDisabled) {
722
+ if (this.menuVisibleOnFocus) {
723
+ this.menuVisibleOnFocus = false;
724
+ } else {
725
+ this.visible = !this.visible;
726
+ }
727
+ if (this.visible) {
728
+ (this.$refs.input || this.$refs.reference).focus();
729
+ }
730
+ }
731
+ },
732
+
733
+ selectOption() {
734
+ if (!this.visible) {
735
+ this.toggleMenu();
736
+ } else {
737
+ if (this.options[this.hoverIndex]) {
738
+ this.handleOptionSelect(this.options[this.hoverIndex]);
739
+ }
740
+ }
741
+ },
742
+
743
+ deleteSelected(event) {
744
+ event.stopPropagation();
745
+ const value = this.multiple ? [] : '';
746
+ this.$emit('input', value);
747
+ this.emitChange(value);
748
+ this.visible = false;
749
+ this.$emit('clear');
750
+ },
751
+
752
+ deleteTag(event, tag) {
753
+ let index = this.selected.indexOf(tag);
754
+ if (index > -1 && !this.selectDisabled) {
755
+ const value = this.value.slice();
756
+ value.splice(index, 1);
757
+ this.$emit('input', value);
758
+ this.emitChange(value);
759
+ this.$emit('remove-tag', tag.value);
760
+ }
761
+ event.stopPropagation();
762
+ },
763
+
764
+ onInputChange() {
765
+ if (this.filterable && this.query !== this.selectedLabel) {
766
+ this.query = this.selectedLabel;
767
+ this.handleQueryChange(this.query);
768
+ }
769
+ },
770
+
771
+ onOptionDestroy(index) {
772
+ if (index > -1) {
773
+ this.optionsCount--;
774
+ this.filteredOptionsCount--;
775
+ this.options.splice(index, 1);
776
+ }
777
+ },
778
+
779
+ resetInputWidth() {
780
+ this.inputWidth = this.$refs.reference.$el.getBoundingClientRect().width;
781
+ },
782
+
783
+ handleResize() {
784
+ this.resetInputWidth();
785
+ if (this.multiple) this.resetInputHeight();
786
+ },
787
+
788
+ checkDefaultFirstOption() {
789
+ this.hoverIndex = -1;
790
+ // highlight the created option
791
+ let hasCreated = false;
792
+ for (let i = this.options.length - 1; i >= 0; i--) {
793
+ if (this.options[i].created) {
794
+ hasCreated = true;
795
+ this.hoverIndex = i;
796
+ break;
797
+ }
798
+ }
799
+ if (hasCreated) return;
800
+ for (let i = 0; i !== this.options.length; ++i) {
801
+ const option = this.options[i];
802
+ if (this.query) {
803
+ // highlight first options that passes the filter
804
+ if (!option.disabled && !option.groupDisabled && option.visible) {
805
+ this.hoverIndex = i;
806
+ break;
807
+ }
808
+ } else {
809
+ // highlight currently selected option
810
+ if (option.itemSelected) {
811
+ this.hoverIndex = i;
812
+ break;
813
+ }
814
+ }
815
+ }
816
+ },
817
+
818
+ getValueKey(item) {
819
+ if (Object.prototype.toString.call(item.value).toLowerCase() !== '[object object]') {
820
+ return item.value;
821
+ } else {
822
+ return getValueByPath(item.value, this.valueKey);
823
+ }
824
+ }
825
+ },
826
+
827
+ created() {
828
+ this.cachedPlaceHolder = this.currentPlaceholder = this.placeholder;
829
+ if (this.multiple && !Array.isArray(this.value)) {
830
+ this.$emit('input', []);
831
+ }
832
+ if (!this.multiple && Array.isArray(this.value)) {
833
+ this.$emit('input', '');
834
+ }
835
+
836
+ this.debouncedOnInputChange = debounce(this.debounce, () => {
837
+ this.onInputChange();
838
+ });
839
+
840
+ this.debouncedQueryChange = debounce(this.debounce, (e) => {
841
+ this.handleQueryChange(e.target.value);
842
+ });
843
+
844
+ this.$on('handleOptionClick', this.handleOptionSelect);
845
+ this.$on('setSelected', this.setSelected);
846
+ },
847
+
848
+ mounted() {
849
+ if (this.multiple && Array.isArray(this.value) && this.value.length > 0) {
850
+ this.currentPlaceholder = '';
851
+ }
852
+ addResizeListener(this.$el, this.handleResize);
853
+
854
+ const reference = this.$refs.reference;
855
+ if (reference && reference.$el) {
856
+ const sizeMap = {
857
+ medium: 36,
858
+ small: 32,
859
+ mini: 28
860
+ };
861
+ this.initialInputHeight = reference.$el.getBoundingClientRect().height || sizeMap[this.selectSize];
862
+ }
863
+ if (this.remote && this.multiple) {
864
+ this.resetInputHeight();
865
+ }
866
+ this.$nextTick(() => {
867
+ if (reference && reference.$el) {
868
+ this.inputWidth = reference.$el.getBoundingClientRect().width;
869
+ }
870
+ });
871
+ this.setSelected();
872
+ },
873
+
874
+ beforeDestroy() {
875
+ if (this.$el && this.handleResize) removeResizeListener(this.$el, this.handleResize);
876
+ }
877
+ };
878
+ </script>