buefy 0.9.13 → 0.9.14
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.
- package/dist/buefy.css +1 -1
- package/dist/buefy.esm.js +167 -117
- package/dist/buefy.esm.min.js +2 -2
- package/dist/buefy.js +168 -116
- package/dist/buefy.min.css +1 -1
- package/dist/buefy.min.js +2 -2
- package/dist/cjs/autocomplete.js +5 -5
- package/dist/cjs/breadcrumb.js +1 -1
- package/dist/cjs/button.js +3 -3
- package/dist/cjs/carousel.js +4 -4
- package/dist/cjs/{chunk-c6fbc7b4.js → chunk-02406b6a.js} +2 -2
- package/dist/cjs/{chunk-d0f8ea39.js → chunk-0cc2e136.js} +6 -6
- package/dist/cjs/{chunk-114191ae.js → chunk-0d901f36.js} +2 -2
- package/dist/cjs/{chunk-9e4cf4c5.js → chunk-1061ac68.js} +1 -1
- package/dist/cjs/{chunk-2c7de785.js → chunk-1d2f05e0.js} +0 -0
- package/dist/cjs/{chunk-30670fac.js → chunk-2a2403f9.js} +78 -62
- package/dist/cjs/{chunk-d54e40f6.js → chunk-2cdb1a89.js} +2 -9
- package/dist/cjs/{chunk-34949503.js → chunk-4a3a5cf7.js} +1 -1
- package/dist/cjs/{chunk-fe2f57ee.js → chunk-4ebee779.js} +2 -2
- package/dist/cjs/{chunk-2062216d.js → chunk-5a7e385c.js} +1 -1
- package/dist/cjs/{chunk-f5106717.js → chunk-74fb31db.js} +3 -3
- package/dist/cjs/{chunk-7da0c017.js → chunk-a267720d.js} +21 -21
- package/dist/cjs/{chunk-a11294f9.js → chunk-a268cb3d.js} +2 -2
- package/dist/cjs/{chunk-c7b2aa4b.js → chunk-bb7da16a.js} +1 -1
- package/dist/cjs/{chunk-2ae50815.js → chunk-bebdaf0b.js} +3 -3
- package/dist/cjs/{chunk-9103eeda.js → chunk-c0adb618.js} +1 -1
- package/dist/cjs/{chunk-d120e215.js → chunk-d7d30e52.js} +1 -1
- package/dist/cjs/{chunk-fefd7b77.js → chunk-ddd15f05.js} +0 -0
- package/dist/cjs/{chunk-2911aa4b.js → chunk-e8dc6270.js} +14 -11
- package/dist/cjs/{chunk-3cc5d9a6.js → chunk-eb8d954b.js} +0 -0
- package/dist/cjs/{chunk-6cb902f8.js → chunk-f536c03f.js} +1 -1
- package/dist/cjs/{chunk-61023b09.js → chunk-fbf3566e.js} +2 -2
- package/dist/cjs/clockpicker.js +8 -8
- package/dist/cjs/config.js +1 -1
- package/dist/cjs/datepicker.js +9 -9
- package/dist/cjs/datetimepicker.js +11 -11
- package/dist/cjs/dialog.js +4 -4
- package/dist/cjs/dropdown.js +3 -3
- package/dist/cjs/field.js +2 -2
- package/dist/cjs/helpers.js +20 -0
- package/dist/cjs/icon.js +2 -2
- package/dist/cjs/image.js +2 -2
- package/dist/cjs/index.js +24 -22
- package/dist/cjs/input.js +4 -4
- package/dist/cjs/loading.js +2 -2
- package/dist/cjs/menu.js +2 -2
- package/dist/cjs/message.js +3 -3
- package/dist/cjs/modal.js +2 -2
- package/dist/cjs/navbar.js +3 -0
- package/dist/cjs/notification.js +4 -4
- package/dist/cjs/numberinput.js +4 -4
- package/dist/cjs/pagination.js +3 -3
- package/dist/cjs/progress.js +2 -2
- package/dist/cjs/rate.js +2 -2
- package/dist/cjs/select.js +4 -4
- package/dist/cjs/sidebar.js +1 -1
- package/dist/cjs/slider.js +2 -2
- package/dist/cjs/snackbar.js +4 -3
- package/dist/cjs/steps.js +5 -5
- package/dist/cjs/switch.js +1 -1
- package/dist/cjs/table.js +24 -22
- package/dist/cjs/tabs.js +7 -7
- package/dist/cjs/taginput.js +5 -5
- package/dist/cjs/timepicker.js +10 -10
- package/dist/cjs/toast.js +2 -2
- package/dist/cjs/tooltip.js +2 -2
- package/dist/cjs/upload.js +21 -7
- package/dist/components/autocomplete/index.js +78 -62
- package/dist/components/autocomplete/index.min.js +2 -2
- package/dist/components/breadcrumb/index.js +2 -2
- package/dist/components/breadcrumb/index.min.js +1 -1
- package/dist/components/button/index.js +2 -2
- package/dist/components/button/index.min.js +2 -2
- package/dist/components/carousel/index.js +2 -2
- package/dist/components/carousel/index.min.js +2 -2
- package/dist/components/checkbox/index.js +1 -1
- package/dist/components/checkbox/index.min.js +1 -1
- package/dist/components/clockpicker/index.js +22 -22
- package/dist/components/clockpicker/index.min.js +2 -2
- package/dist/components/collapse/index.js +1 -1
- package/dist/components/collapse/index.min.js +1 -1
- package/dist/components/datepicker/index.js +29 -26
- package/dist/components/datepicker/index.min.js +2 -2
- package/dist/components/datetimepicker/index.js +29 -26
- package/dist/components/datetimepicker/index.min.js +2 -2
- package/dist/components/dialog/index.js +2 -2
- package/dist/components/dialog/index.min.js +2 -2
- package/dist/components/dropdown/index.js +2 -2
- package/dist/components/dropdown/index.min.js +1 -1
- package/dist/components/field/index.js +22 -22
- package/dist/components/field/index.min.js +1 -1
- package/dist/components/icon/index.js +2 -2
- package/dist/components/icon/index.min.js +2 -2
- package/dist/components/image/index.js +2 -2
- package/dist/components/image/index.min.js +2 -2
- package/dist/components/input/index.js +2 -2
- package/dist/components/input/index.min.js +2 -2
- package/dist/components/loading/index.js +1 -1
- package/dist/components/loading/index.min.js +1 -1
- package/dist/components/menu/index.js +2 -2
- package/dist/components/menu/index.min.js +2 -2
- package/dist/components/message/index.js +2 -2
- package/dist/components/message/index.min.js +2 -2
- package/dist/components/modal/index.js +2 -2
- package/dist/components/modal/index.min.js +2 -2
- package/dist/components/navbar/index.js +4 -1
- package/dist/components/navbar/index.min.js +2 -2
- package/dist/components/notification/index.js +3 -10
- package/dist/components/notification/index.min.js +2 -2
- package/dist/components/numberinput/index.js +2 -2
- package/dist/components/numberinput/index.min.js +2 -2
- package/dist/components/pagination/index.js +2 -2
- package/dist/components/pagination/index.min.js +2 -2
- package/dist/components/progress/index.js +2 -2
- package/dist/components/progress/index.min.js +2 -2
- package/dist/components/radio/index.js +1 -1
- package/dist/components/radio/index.min.js +1 -1
- package/dist/components/rate/index.js +2 -2
- package/dist/components/rate/index.min.js +2 -2
- package/dist/components/select/index.js +2 -2
- package/dist/components/select/index.min.js +2 -2
- package/dist/components/sidebar/index.js +2 -2
- package/dist/components/sidebar/index.min.js +1 -1
- package/dist/components/skeleton/index.js +1 -1
- package/dist/components/skeleton/index.min.js +1 -1
- package/dist/components/slider/index.js +2 -2
- package/dist/components/slider/index.min.js +2 -2
- package/dist/components/snackbar/index.js +5 -11
- package/dist/components/snackbar/index.min.js +2 -2
- package/dist/components/steps/index.js +2 -2
- package/dist/components/steps/index.min.js +2 -2
- package/dist/components/switch/index.js +2 -2
- package/dist/components/switch/index.min.js +1 -1
- package/dist/components/table/index.js +36 -16
- package/dist/components/table/index.min.js +2 -2
- package/dist/components/tabs/index.js +4 -4
- package/dist/components/tabs/index.min.js +2 -2
- package/dist/components/tag/index.js +1 -1
- package/dist/components/tag/index.min.js +1 -1
- package/dist/components/taginput/index.js +78 -62
- package/dist/components/taginput/index.min.js +2 -2
- package/dist/components/timepicker/index.js +22 -22
- package/dist/components/timepicker/index.min.js +2 -2
- package/dist/components/toast/index.js +3 -10
- package/dist/components/toast/index.min.js +2 -2
- package/dist/components/tooltip/index.js +2 -2
- package/dist/components/tooltip/index.min.js +1 -1
- package/dist/components/upload/index.js +21 -7
- package/dist/components/upload/index.min.js +2 -2
- package/dist/esm/autocomplete.js +6 -6
- package/dist/esm/breadcrumb.js +1 -1
- package/dist/esm/button.js +4 -4
- package/dist/esm/carousel.js +4 -4
- package/dist/esm/{chunk-21fc0948.js → chunk-03f0ac1a.js} +6 -6
- package/dist/esm/{chunk-b0c0c6b0.js → chunk-0c4e4e90.js} +0 -0
- package/dist/esm/{chunk-ae8ab23a.js → chunk-113685dc.js} +3 -3
- package/dist/esm/{chunk-71a547bc.js → chunk-1b63211c.js} +1 -1
- package/dist/esm/{chunk-d7f92d97.js → chunk-1f41edb4.js} +1 -1
- package/dist/esm/{chunk-3773c62d.js → chunk-2229e354.js} +1 -1
- package/dist/esm/{chunk-83eb0d37.js → chunk-40f06d9c.js} +2 -2
- package/dist/esm/{chunk-75a5af93.js → chunk-590a6902.js} +1 -1
- package/dist/esm/{chunk-22e9f916.js → chunk-5f0c3fc4.js} +14 -11
- package/dist/esm/{chunk-6019fd7a.js → chunk-79ac4d01.js} +79 -63
- package/dist/esm/{chunk-8ed29c41.js → chunk-8cad1844.js} +1 -1
- package/dist/esm/{chunk-29ca0df8.js → chunk-91404fa9.js} +0 -0
- package/dist/esm/{chunk-b07e3182.js → chunk-97f201e0.js} +21 -21
- package/dist/esm/{chunk-c9c58d0c.js → chunk-9e0ae963.js} +0 -0
- package/dist/esm/{chunk-ece062a7.js → chunk-a8516afd.js} +2 -2
- package/dist/esm/{chunk-4b67a181.js → chunk-b66a83ce.js} +2 -2
- package/dist/esm/{chunk-9f7f7441.js → chunk-b99e83bd.js} +1 -1
- package/dist/esm/{chunk-18e8b067.js → chunk-bbf5d78a.js} +2 -2
- package/dist/esm/{chunk-8d0f95b8.js → chunk-e01e9ef0.js} +3 -3
- package/dist/esm/{chunk-799e084d.js → chunk-e7eb83d8.js} +2 -9
- package/dist/esm/{chunk-d92f0cd9.js → chunk-ea9bc877.js} +1 -1
- package/dist/esm/{chunk-e7c9b2cb.js → chunk-efec59b6.js} +2 -2
- package/dist/esm/clockpicker.js +8 -8
- package/dist/esm/config.js +1 -1
- package/dist/esm/datepicker.js +10 -10
- package/dist/esm/datetimepicker.js +11 -11
- package/dist/esm/dialog.js +4 -4
- package/dist/esm/dropdown.js +4 -4
- package/dist/esm/field.js +3 -3
- package/dist/esm/helpers.js +19 -1
- package/dist/esm/icon.js +3 -3
- package/dist/esm/image.js +3 -3
- package/dist/esm/index.js +23 -23
- package/dist/esm/input.js +5 -5
- package/dist/esm/loading.js +3 -3
- package/dist/esm/menu.js +2 -2
- package/dist/esm/message.js +3 -3
- package/dist/esm/modal.js +3 -3
- package/dist/esm/navbar.js +3 -0
- package/dist/esm/notification.js +4 -4
- package/dist/esm/numberinput.js +4 -4
- package/dist/esm/pagination.js +4 -4
- package/dist/esm/progress.js +2 -2
- package/dist/esm/rate.js +2 -2
- package/dist/esm/select.js +5 -5
- package/dist/esm/sidebar.js +1 -1
- package/dist/esm/slider.js +2 -2
- package/dist/esm/snackbar.js +4 -3
- package/dist/esm/steps.js +5 -5
- package/dist/esm/switch.js +1 -1
- package/dist/esm/table.js +25 -23
- package/dist/esm/tabs.js +7 -7
- package/dist/esm/taginput.js +5 -5
- package/dist/esm/timepicker.js +11 -11
- package/dist/esm/toast.js +2 -2
- package/dist/esm/tooltip.js +3 -3
- package/dist/esm/upload.js +21 -7
- package/dist/vetur/attributes.json +4 -0
- package/dist/vetur/tags.json +1 -0
- package/package.json +1 -1
- package/src/components/autocomplete/Autocomplete.vue +711 -701
- package/src/components/breadcrumb/__snapshots__/BreadcrumbItem.spec.js.snap +1 -5
- package/src/components/carousel/__snapshots__/CarouselList.spec.js.snap +48 -48
- package/src/components/datepicker/DatepickerTableRow.spec.js +26 -0
- package/src/components/datepicker/DatepickerTableRow.vue +4 -5
- package/src/components/field/Field.vue +271 -271
- package/src/components/navbar/NavbarDropdown.vue +4 -0
- package/src/components/snackbar/index.js +2 -1
- package/src/components/table/Table.spec.js +17 -3
- package/src/components/table/Table.vue +8 -9
- package/src/components/tabs/Tabs.vue +185 -183
- package/src/components/timepicker/__snapshots__/Timepicker.spec.js.snap +18 -47
- package/src/components/upload/Upload.vue +19 -7
- package/src/utils/NoticeMixin.js +1 -5
- package/src/utils/config.js +1 -1
- package/src/utils/helpers.js +16 -0
- package/types/components.d.ts +5 -0
|
@@ -1,701 +1,711 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<div class="autocomplete control" :class="{ 'is-expanded': expanded }">
|
|
3
|
-
<b-input
|
|
4
|
-
v-model="newValue"
|
|
5
|
-
ref="input"
|
|
6
|
-
:type="type"
|
|
7
|
-
:size="size"
|
|
8
|
-
:loading="loading"
|
|
9
|
-
:rounded="rounded"
|
|
10
|
-
:icon="icon"
|
|
11
|
-
:icon-right="newIconRight"
|
|
12
|
-
:icon-right-clickable="newIconRightClickable"
|
|
13
|
-
:icon-pack="iconPack"
|
|
14
|
-
:maxlength="maxlength"
|
|
15
|
-
:autocomplete="newAutocomplete"
|
|
16
|
-
:use-html5-validation="false"
|
|
17
|
-
:aria-autocomplete="ariaAutocomplete"
|
|
18
|
-
v-bind="$attrs"
|
|
19
|
-
@input="onInput"
|
|
20
|
-
@focus="focused"
|
|
21
|
-
@blur="onBlur"
|
|
22
|
-
@keydown.native="keydown"
|
|
23
|
-
@keydown.native.up.prevent="keyArrows('up')"
|
|
24
|
-
@keydown.native.down.prevent="keyArrows('down')"
|
|
25
|
-
@icon-right-click="rightIconClick"
|
|
26
|
-
@icon-click="(event) => $emit('icon-click', event)"
|
|
27
|
-
/>
|
|
28
|
-
|
|
29
|
-
<transition name="fade">
|
|
30
|
-
<div
|
|
31
|
-
class="dropdown-menu"
|
|
32
|
-
:class="{ 'is-opened-top': isOpenedTop && !appendToBody }"
|
|
33
|
-
:style="style"
|
|
34
|
-
v-show="isActive && (!isEmpty || hasEmptySlot || hasHeaderSlot)"
|
|
35
|
-
ref="dropdown"
|
|
36
|
-
>
|
|
37
|
-
<div
|
|
38
|
-
class="dropdown-content"
|
|
39
|
-
v-show="isActive"
|
|
40
|
-
:style="contentStyle">
|
|
41
|
-
<div
|
|
42
|
-
v-if="hasHeaderSlot"
|
|
43
|
-
class="dropdown-item dropdown-header"
|
|
44
|
-
role="button"
|
|
45
|
-
tabindex="0"
|
|
46
|
-
:class="{ 'is-hovered': headerHovered }"
|
|
47
|
-
@click="selectHeaderOrFoterByClick($event, 'header')"
|
|
48
|
-
>
|
|
49
|
-
<slot name="header" />
|
|
50
|
-
</div>
|
|
51
|
-
<template v-for="(element, groupindex) in computedData">
|
|
52
|
-
<div
|
|
53
|
-
v-if="element.group"
|
|
54
|
-
:key="groupindex + 'group'"
|
|
55
|
-
class="dropdown-item">
|
|
56
|
-
<slot
|
|
57
|
-
v-if="hasGroupSlot"
|
|
58
|
-
name="group"
|
|
59
|
-
:group="element.group"
|
|
60
|
-
:index="groupindex" />
|
|
61
|
-
<span class="has-text-weight-bold" v-else>
|
|
62
|
-
{{ element.group }}
|
|
63
|
-
</span>
|
|
64
|
-
</div>
|
|
65
|
-
<a
|
|
66
|
-
v-for="(option, index) in element.items"
|
|
67
|
-
:key="groupindex + ':' + index"
|
|
68
|
-
class="dropdown-item"
|
|
69
|
-
role="button"
|
|
70
|
-
tabindex="0"
|
|
71
|
-
:class="{ 'is-hovered': option === hovered }"
|
|
72
|
-
@click.stop="setSelected(option, !keepOpen, $event)"
|
|
73
|
-
>
|
|
74
|
-
<slot
|
|
75
|
-
v-if="hasDefaultSlot"
|
|
76
|
-
:option="option"
|
|
77
|
-
:index="index" />
|
|
78
|
-
<span v-else>
|
|
79
|
-
{{ getValue(option, true) }}
|
|
80
|
-
</span>
|
|
81
|
-
</a>
|
|
82
|
-
</template>
|
|
83
|
-
<div
|
|
84
|
-
v-if="isEmpty && hasEmptySlot"
|
|
85
|
-
class="dropdown-item is-disabled">
|
|
86
|
-
<slot name="empty" />
|
|
87
|
-
</div>
|
|
88
|
-
<div
|
|
89
|
-
v-if="hasFooterSlot"
|
|
90
|
-
class="dropdown-item dropdown-footer"
|
|
91
|
-
role="button"
|
|
92
|
-
tabindex="0"
|
|
93
|
-
:class="{ 'is-hovered': footerHovered }"
|
|
94
|
-
@click="selectHeaderOrFoterByClick($event, 'footer')"
|
|
95
|
-
>
|
|
96
|
-
<slot name="footer" />
|
|
97
|
-
</div>
|
|
98
|
-
</div>
|
|
99
|
-
</div>
|
|
100
|
-
</transition>
|
|
101
|
-
</div>
|
|
102
|
-
</template>
|
|
103
|
-
|
|
104
|
-
<script>
|
|
105
|
-
import {
|
|
106
|
-
getValueByPath,
|
|
107
|
-
removeElement,
|
|
108
|
-
createAbsoluteElement,
|
|
109
|
-
isCustomElement,
|
|
110
|
-
toCssWidth
|
|
111
|
-
} from '../../utils/helpers'
|
|
112
|
-
import FormElementMixin from '../../utils/FormElementMixin'
|
|
113
|
-
import Input from '../input/Input'
|
|
114
|
-
|
|
115
|
-
export default {
|
|
116
|
-
name: 'BAutocomplete',
|
|
117
|
-
components: {
|
|
118
|
-
[Input.name]: Input
|
|
119
|
-
},
|
|
120
|
-
mixins: [FormElementMixin],
|
|
121
|
-
inheritAttrs: false,
|
|
122
|
-
props: {
|
|
123
|
-
value: [Number, String],
|
|
124
|
-
data: {
|
|
125
|
-
type: Array,
|
|
126
|
-
default: () => []
|
|
127
|
-
},
|
|
128
|
-
field: {
|
|
129
|
-
type: String,
|
|
130
|
-
default: 'value'
|
|
131
|
-
},
|
|
132
|
-
keepFirst: Boolean,
|
|
133
|
-
clearOnSelect: Boolean,
|
|
134
|
-
openOnFocus: Boolean,
|
|
135
|
-
customFormatter: Function,
|
|
136
|
-
checkInfiniteScroll: Boolean,
|
|
137
|
-
keepOpen: Boolean,
|
|
138
|
-
selectOnClickOutside: Boolean,
|
|
139
|
-
clearable: Boolean,
|
|
140
|
-
maxHeight: [String, Number],
|
|
141
|
-
dropdownPosition: {
|
|
142
|
-
type: String,
|
|
143
|
-
default: 'auto'
|
|
144
|
-
},
|
|
145
|
-
groupField: String,
|
|
146
|
-
groupOptions: String,
|
|
147
|
-
iconRight: String,
|
|
148
|
-
iconRightClickable: Boolean,
|
|
149
|
-
appendToBody: Boolean,
|
|
150
|
-
type: {
|
|
151
|
-
type: String,
|
|
152
|
-
default: 'text'
|
|
153
|
-
},
|
|
154
|
-
confirmKeys: {
|
|
155
|
-
type: Array,
|
|
156
|
-
default: () => ['Tab', 'Enter']
|
|
157
|
-
},
|
|
158
|
-
selectableHeader: Boolean,
|
|
159
|
-
selectableFooter: Boolean
|
|
160
|
-
},
|
|
161
|
-
data() {
|
|
162
|
-
return {
|
|
163
|
-
selected: null,
|
|
164
|
-
hovered: null,
|
|
165
|
-
headerHovered: null,
|
|
166
|
-
footerHovered: null,
|
|
167
|
-
isActive: false,
|
|
168
|
-
newValue: this.value,
|
|
169
|
-
newAutocomplete: this.autocomplete || 'off',
|
|
170
|
-
ariaAutocomplete: this.keepFirst ? 'both' : 'list',
|
|
171
|
-
isListInViewportVertically: true,
|
|
172
|
-
hasFocus: false,
|
|
173
|
-
style: {},
|
|
174
|
-
_isAutocomplete: true,
|
|
175
|
-
_elementRef: 'input',
|
|
176
|
-
_bodyEl: undefined // Used to append to body
|
|
177
|
-
}
|
|
178
|
-
},
|
|
179
|
-
computed: {
|
|
180
|
-
computedData() {
|
|
181
|
-
if (this.groupField) {
|
|
182
|
-
if (this.groupOptions) {
|
|
183
|
-
const newData = []
|
|
184
|
-
this.data.forEach((option) => {
|
|
185
|
-
const group = getValueByPath(option, this.groupField)
|
|
186
|
-
const items = getValueByPath(option, this.groupOptions)
|
|
187
|
-
newData.push({ group, items })
|
|
188
|
-
})
|
|
189
|
-
return newData
|
|
190
|
-
} else {
|
|
191
|
-
const tmp = {}
|
|
192
|
-
this.data.forEach((option) => {
|
|
193
|
-
const group = getValueByPath(option, this.groupField)
|
|
194
|
-
if (!tmp[group]) tmp[group] = []
|
|
195
|
-
tmp[group].push(option)
|
|
196
|
-
})
|
|
197
|
-
const newData = []
|
|
198
|
-
Object.keys(tmp).forEach((group) => {
|
|
199
|
-
newData.push({ group, items: tmp[group] })
|
|
200
|
-
})
|
|
201
|
-
return newData
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
return [{ items: this.data }]
|
|
205
|
-
},
|
|
206
|
-
isEmpty() {
|
|
207
|
-
if (!this.computedData) return true
|
|
208
|
-
return !this.computedData.some((element) => element.items && element.items.length)
|
|
209
|
-
},
|
|
210
|
-
/**
|
|
211
|
-
* White-listed items to not close when clicked.
|
|
212
|
-
* Add input, dropdown and all children.
|
|
213
|
-
*/
|
|
214
|
-
whiteList() {
|
|
215
|
-
const whiteList = []
|
|
216
|
-
whiteList.push(this.$refs.input.$el.querySelector('input'))
|
|
217
|
-
whiteList.push(this.$refs.dropdown)
|
|
218
|
-
// Add all children from dropdown
|
|
219
|
-
if (this.$refs.dropdown !== undefined) {
|
|
220
|
-
const children = this.$refs.dropdown.querySelectorAll('*')
|
|
221
|
-
for (const child of children) {
|
|
222
|
-
whiteList.push(child)
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
if (this.$parent.$data._isTaginput) {
|
|
226
|
-
// Add taginput container
|
|
227
|
-
whiteList.push(this.$parent.$el)
|
|
228
|
-
// Add .tag and .delete
|
|
229
|
-
const tagInputChildren = this.$parent.$el.querySelectorAll('*')
|
|
230
|
-
for (const tagInputChild of tagInputChildren) {
|
|
231
|
-
whiteList.push(tagInputChild)
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
return whiteList
|
|
236
|
-
},
|
|
237
|
-
|
|
238
|
-
/**
|
|
239
|
-
* Check if exists default slot
|
|
240
|
-
*/
|
|
241
|
-
hasDefaultSlot() {
|
|
242
|
-
return !!this.$scopedSlots.default
|
|
243
|
-
},
|
|
244
|
-
|
|
245
|
-
/**
|
|
246
|
-
* Check if exists group slot
|
|
247
|
-
*/
|
|
248
|
-
hasGroupSlot() {
|
|
249
|
-
return !!this.$scopedSlots.group
|
|
250
|
-
},
|
|
251
|
-
|
|
252
|
-
/**
|
|
253
|
-
* Check if exists "empty" slot
|
|
254
|
-
*/
|
|
255
|
-
hasEmptySlot() {
|
|
256
|
-
return !!this.$slots.empty
|
|
257
|
-
},
|
|
258
|
-
|
|
259
|
-
/**
|
|
260
|
-
* Check if exists "header" slot
|
|
261
|
-
*/
|
|
262
|
-
hasHeaderSlot() {
|
|
263
|
-
return !!this.$slots.header
|
|
264
|
-
},
|
|
265
|
-
|
|
266
|
-
/**
|
|
267
|
-
* Check if exists "footer" slot
|
|
268
|
-
*/
|
|
269
|
-
hasFooterSlot() {
|
|
270
|
-
return !!this.$slots.footer
|
|
271
|
-
},
|
|
272
|
-
|
|
273
|
-
/**
|
|
274
|
-
* Apply dropdownPosition property
|
|
275
|
-
*/
|
|
276
|
-
isOpenedTop() {
|
|
277
|
-
return (
|
|
278
|
-
this.dropdownPosition === 'top' ||
|
|
279
|
-
(this.dropdownPosition === 'auto' && !this.isListInViewportVertically)
|
|
280
|
-
)
|
|
281
|
-
},
|
|
282
|
-
|
|
283
|
-
newIconRight() {
|
|
284
|
-
if (this.clearable && this.newValue) {
|
|
285
|
-
return 'close-circle'
|
|
286
|
-
}
|
|
287
|
-
return this.iconRight
|
|
288
|
-
},
|
|
289
|
-
|
|
290
|
-
newIconRightClickable() {
|
|
291
|
-
if (this.clearable) {
|
|
292
|
-
return true
|
|
293
|
-
}
|
|
294
|
-
return this.iconRightClickable
|
|
295
|
-
},
|
|
296
|
-
|
|
297
|
-
contentStyle() {
|
|
298
|
-
return {
|
|
299
|
-
maxHeight: toCssWidth(this.maxHeight)
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
},
|
|
303
|
-
watch: {
|
|
304
|
-
/**
|
|
305
|
-
* When dropdown is toggled, check the visibility to know when
|
|
306
|
-
* to open upwards.
|
|
307
|
-
*/
|
|
308
|
-
isActive(active) {
|
|
309
|
-
if (this.dropdownPosition === 'auto') {
|
|
310
|
-
if (active) {
|
|
311
|
-
this.calcDropdownInViewportVertical()
|
|
312
|
-
} else {
|
|
313
|
-
// Timeout to wait for the animation to finish before recalculating
|
|
314
|
-
setTimeout(() => {
|
|
315
|
-
this.calcDropdownInViewportVertical()
|
|
316
|
-
}, 100)
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
},
|
|
320
|
-
|
|
321
|
-
/**
|
|
322
|
-
* When updating input's value
|
|
323
|
-
* 1. Emit changes
|
|
324
|
-
* 2. If value isn't the same as selected, set null
|
|
325
|
-
* 3. Close dropdown if value is clear or else open it
|
|
326
|
-
*/
|
|
327
|
-
newValue(value) {
|
|
328
|
-
this.$emit('input', value)
|
|
329
|
-
// Check if selected is invalid
|
|
330
|
-
const currentValue = this.getValue(this.selected)
|
|
331
|
-
if (currentValue && currentValue !== value) {
|
|
332
|
-
this.setSelected(null, false)
|
|
333
|
-
}
|
|
334
|
-
// Close dropdown if input is clear or else open it
|
|
335
|
-
if (this.hasFocus && (!this.openOnFocus || value)) {
|
|
336
|
-
this.isActive = !!value
|
|
337
|
-
}
|
|
338
|
-
},
|
|
339
|
-
|
|
340
|
-
/**
|
|
341
|
-
* When v-model is changed:
|
|
342
|
-
* 1. Update internal value.
|
|
343
|
-
* 2. If it's invalid, validate again.
|
|
344
|
-
*/
|
|
345
|
-
value(value) {
|
|
346
|
-
this.newValue = value
|
|
347
|
-
},
|
|
348
|
-
|
|
349
|
-
/**
|
|
350
|
-
* Select first option if "keep-first
|
|
351
|
-
*/
|
|
352
|
-
data() {
|
|
353
|
-
// Keep first option always pre-selected
|
|
354
|
-
if (this.keepFirst) {
|
|
355
|
-
this.$nextTick(() => {
|
|
356
|
-
if (this.isActive) {
|
|
357
|
-
this.selectFirstOption(this.computedData)
|
|
358
|
-
} else {
|
|
359
|
-
this.setHovered(null)
|
|
360
|
-
}
|
|
361
|
-
})
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
*
|
|
378
|
-
*/
|
|
379
|
-
|
|
380
|
-
if (option === undefined) return
|
|
381
|
-
|
|
382
|
-
this
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
this.
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
this.$nextTick(() => {
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
if (
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
)
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
}
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
this.
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
this.
|
|
556
|
-
}
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
if (
|
|
577
|
-
|
|
578
|
-
}
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
this
|
|
593
|
-
}
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
this.
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
this
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
}
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
}
|
|
690
|
-
if (this.
|
|
691
|
-
this.$
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
if (
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
1
|
+
<template>
|
|
2
|
+
<div class="autocomplete control" :class="{ 'is-expanded': expanded }">
|
|
3
|
+
<b-input
|
|
4
|
+
v-model="newValue"
|
|
5
|
+
ref="input"
|
|
6
|
+
:type="type"
|
|
7
|
+
:size="size"
|
|
8
|
+
:loading="loading"
|
|
9
|
+
:rounded="rounded"
|
|
10
|
+
:icon="icon"
|
|
11
|
+
:icon-right="newIconRight"
|
|
12
|
+
:icon-right-clickable="newIconRightClickable"
|
|
13
|
+
:icon-pack="iconPack"
|
|
14
|
+
:maxlength="maxlength"
|
|
15
|
+
:autocomplete="newAutocomplete"
|
|
16
|
+
:use-html5-validation="false"
|
|
17
|
+
:aria-autocomplete="ariaAutocomplete"
|
|
18
|
+
v-bind="$attrs"
|
|
19
|
+
@input="onInput"
|
|
20
|
+
@focus="focused"
|
|
21
|
+
@blur="onBlur"
|
|
22
|
+
@keydown.native="keydown"
|
|
23
|
+
@keydown.native.up.prevent="keyArrows('up')"
|
|
24
|
+
@keydown.native.down.prevent="keyArrows('down')"
|
|
25
|
+
@icon-right-click="rightIconClick"
|
|
26
|
+
@icon-click="(event) => $emit('icon-click', event)"
|
|
27
|
+
/>
|
|
28
|
+
|
|
29
|
+
<transition name="fade">
|
|
30
|
+
<div
|
|
31
|
+
class="dropdown-menu"
|
|
32
|
+
:class="{ 'is-opened-top': isOpenedTop && !appendToBody }"
|
|
33
|
+
:style="style"
|
|
34
|
+
v-show="isActive && (!isEmpty || hasEmptySlot || hasHeaderSlot)"
|
|
35
|
+
ref="dropdown"
|
|
36
|
+
>
|
|
37
|
+
<div
|
|
38
|
+
class="dropdown-content"
|
|
39
|
+
v-show="isActive"
|
|
40
|
+
:style="contentStyle">
|
|
41
|
+
<div
|
|
42
|
+
v-if="hasHeaderSlot"
|
|
43
|
+
class="dropdown-item dropdown-header"
|
|
44
|
+
role="button"
|
|
45
|
+
tabindex="0"
|
|
46
|
+
:class="{ 'is-hovered': headerHovered }"
|
|
47
|
+
@click="selectHeaderOrFoterByClick($event, 'header')"
|
|
48
|
+
>
|
|
49
|
+
<slot name="header" />
|
|
50
|
+
</div>
|
|
51
|
+
<template v-for="(element, groupindex) in computedData">
|
|
52
|
+
<div
|
|
53
|
+
v-if="element.group"
|
|
54
|
+
:key="groupindex + 'group'"
|
|
55
|
+
class="dropdown-item">
|
|
56
|
+
<slot
|
|
57
|
+
v-if="hasGroupSlot"
|
|
58
|
+
name="group"
|
|
59
|
+
:group="element.group"
|
|
60
|
+
:index="groupindex" />
|
|
61
|
+
<span class="has-text-weight-bold" v-else>
|
|
62
|
+
{{ element.group }}
|
|
63
|
+
</span>
|
|
64
|
+
</div>
|
|
65
|
+
<a
|
|
66
|
+
v-for="(option, index) in element.items"
|
|
67
|
+
:key="groupindex + ':' + index"
|
|
68
|
+
class="dropdown-item"
|
|
69
|
+
role="button"
|
|
70
|
+
tabindex="0"
|
|
71
|
+
:class="{ 'is-hovered': option === hovered }"
|
|
72
|
+
@click.stop="setSelected(option, !keepOpen, $event)"
|
|
73
|
+
>
|
|
74
|
+
<slot
|
|
75
|
+
v-if="hasDefaultSlot"
|
|
76
|
+
:option="option"
|
|
77
|
+
:index="index" />
|
|
78
|
+
<span v-else>
|
|
79
|
+
{{ getValue(option, true) }}
|
|
80
|
+
</span>
|
|
81
|
+
</a>
|
|
82
|
+
</template>
|
|
83
|
+
<div
|
|
84
|
+
v-if="isEmpty && hasEmptySlot"
|
|
85
|
+
class="dropdown-item is-disabled">
|
|
86
|
+
<slot name="empty" />
|
|
87
|
+
</div>
|
|
88
|
+
<div
|
|
89
|
+
v-if="hasFooterSlot"
|
|
90
|
+
class="dropdown-item dropdown-footer"
|
|
91
|
+
role="button"
|
|
92
|
+
tabindex="0"
|
|
93
|
+
:class="{ 'is-hovered': footerHovered }"
|
|
94
|
+
@click="selectHeaderOrFoterByClick($event, 'footer')"
|
|
95
|
+
>
|
|
96
|
+
<slot name="footer" />
|
|
97
|
+
</div>
|
|
98
|
+
</div>
|
|
99
|
+
</div>
|
|
100
|
+
</transition>
|
|
101
|
+
</div>
|
|
102
|
+
</template>
|
|
103
|
+
|
|
104
|
+
<script>
|
|
105
|
+
import {
|
|
106
|
+
getValueByPath,
|
|
107
|
+
removeElement,
|
|
108
|
+
createAbsoluteElement,
|
|
109
|
+
isCustomElement,
|
|
110
|
+
toCssWidth
|
|
111
|
+
} from '../../utils/helpers'
|
|
112
|
+
import FormElementMixin from '../../utils/FormElementMixin'
|
|
113
|
+
import Input from '../input/Input'
|
|
114
|
+
|
|
115
|
+
export default {
|
|
116
|
+
name: 'BAutocomplete',
|
|
117
|
+
components: {
|
|
118
|
+
[Input.name]: Input
|
|
119
|
+
},
|
|
120
|
+
mixins: [FormElementMixin],
|
|
121
|
+
inheritAttrs: false,
|
|
122
|
+
props: {
|
|
123
|
+
value: [Number, String],
|
|
124
|
+
data: {
|
|
125
|
+
type: Array,
|
|
126
|
+
default: () => []
|
|
127
|
+
},
|
|
128
|
+
field: {
|
|
129
|
+
type: String,
|
|
130
|
+
default: 'value'
|
|
131
|
+
},
|
|
132
|
+
keepFirst: Boolean,
|
|
133
|
+
clearOnSelect: Boolean,
|
|
134
|
+
openOnFocus: Boolean,
|
|
135
|
+
customFormatter: Function,
|
|
136
|
+
checkInfiniteScroll: Boolean,
|
|
137
|
+
keepOpen: Boolean,
|
|
138
|
+
selectOnClickOutside: Boolean,
|
|
139
|
+
clearable: Boolean,
|
|
140
|
+
maxHeight: [String, Number],
|
|
141
|
+
dropdownPosition: {
|
|
142
|
+
type: String,
|
|
143
|
+
default: 'auto'
|
|
144
|
+
},
|
|
145
|
+
groupField: String,
|
|
146
|
+
groupOptions: String,
|
|
147
|
+
iconRight: String,
|
|
148
|
+
iconRightClickable: Boolean,
|
|
149
|
+
appendToBody: Boolean,
|
|
150
|
+
type: {
|
|
151
|
+
type: String,
|
|
152
|
+
default: 'text'
|
|
153
|
+
},
|
|
154
|
+
confirmKeys: {
|
|
155
|
+
type: Array,
|
|
156
|
+
default: () => ['Tab', 'Enter']
|
|
157
|
+
},
|
|
158
|
+
selectableHeader: Boolean,
|
|
159
|
+
selectableFooter: Boolean
|
|
160
|
+
},
|
|
161
|
+
data() {
|
|
162
|
+
return {
|
|
163
|
+
selected: null,
|
|
164
|
+
hovered: null,
|
|
165
|
+
headerHovered: null,
|
|
166
|
+
footerHovered: null,
|
|
167
|
+
isActive: false,
|
|
168
|
+
newValue: this.value,
|
|
169
|
+
newAutocomplete: this.autocomplete || 'off',
|
|
170
|
+
ariaAutocomplete: this.keepFirst ? 'both' : 'list',
|
|
171
|
+
isListInViewportVertically: true,
|
|
172
|
+
hasFocus: false,
|
|
173
|
+
style: {},
|
|
174
|
+
_isAutocomplete: true,
|
|
175
|
+
_elementRef: 'input',
|
|
176
|
+
_bodyEl: undefined // Used to append to body
|
|
177
|
+
}
|
|
178
|
+
},
|
|
179
|
+
computed: {
|
|
180
|
+
computedData() {
|
|
181
|
+
if (this.groupField) {
|
|
182
|
+
if (this.groupOptions) {
|
|
183
|
+
const newData = []
|
|
184
|
+
this.data.forEach((option) => {
|
|
185
|
+
const group = getValueByPath(option, this.groupField)
|
|
186
|
+
const items = getValueByPath(option, this.groupOptions)
|
|
187
|
+
newData.push({ group, items })
|
|
188
|
+
})
|
|
189
|
+
return newData
|
|
190
|
+
} else {
|
|
191
|
+
const tmp = {}
|
|
192
|
+
this.data.forEach((option) => {
|
|
193
|
+
const group = getValueByPath(option, this.groupField)
|
|
194
|
+
if (!tmp[group]) tmp[group] = []
|
|
195
|
+
tmp[group].push(option)
|
|
196
|
+
})
|
|
197
|
+
const newData = []
|
|
198
|
+
Object.keys(tmp).forEach((group) => {
|
|
199
|
+
newData.push({ group, items: tmp[group] })
|
|
200
|
+
})
|
|
201
|
+
return newData
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
return [{ items: this.data }]
|
|
205
|
+
},
|
|
206
|
+
isEmpty() {
|
|
207
|
+
if (!this.computedData) return true
|
|
208
|
+
return !this.computedData.some((element) => element.items && element.items.length)
|
|
209
|
+
},
|
|
210
|
+
/**
|
|
211
|
+
* White-listed items to not close when clicked.
|
|
212
|
+
* Add input, dropdown and all children.
|
|
213
|
+
*/
|
|
214
|
+
whiteList() {
|
|
215
|
+
const whiteList = []
|
|
216
|
+
whiteList.push(this.$refs.input.$el.querySelector('input'))
|
|
217
|
+
whiteList.push(this.$refs.dropdown)
|
|
218
|
+
// Add all children from dropdown
|
|
219
|
+
if (this.$refs.dropdown !== undefined) {
|
|
220
|
+
const children = this.$refs.dropdown.querySelectorAll('*')
|
|
221
|
+
for (const child of children) {
|
|
222
|
+
whiteList.push(child)
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
if (this.$parent.$data._isTaginput) {
|
|
226
|
+
// Add taginput container
|
|
227
|
+
whiteList.push(this.$parent.$el)
|
|
228
|
+
// Add .tag and .delete
|
|
229
|
+
const tagInputChildren = this.$parent.$el.querySelectorAll('*')
|
|
230
|
+
for (const tagInputChild of tagInputChildren) {
|
|
231
|
+
whiteList.push(tagInputChild)
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
return whiteList
|
|
236
|
+
},
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* Check if exists default slot
|
|
240
|
+
*/
|
|
241
|
+
hasDefaultSlot() {
|
|
242
|
+
return !!this.$scopedSlots.default
|
|
243
|
+
},
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* Check if exists group slot
|
|
247
|
+
*/
|
|
248
|
+
hasGroupSlot() {
|
|
249
|
+
return !!this.$scopedSlots.group
|
|
250
|
+
},
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* Check if exists "empty" slot
|
|
254
|
+
*/
|
|
255
|
+
hasEmptySlot() {
|
|
256
|
+
return !!this.$slots.empty
|
|
257
|
+
},
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* Check if exists "header" slot
|
|
261
|
+
*/
|
|
262
|
+
hasHeaderSlot() {
|
|
263
|
+
return !!this.$slots.header
|
|
264
|
+
},
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* Check if exists "footer" slot
|
|
268
|
+
*/
|
|
269
|
+
hasFooterSlot() {
|
|
270
|
+
return !!this.$slots.footer
|
|
271
|
+
},
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* Apply dropdownPosition property
|
|
275
|
+
*/
|
|
276
|
+
isOpenedTop() {
|
|
277
|
+
return (
|
|
278
|
+
this.dropdownPosition === 'top' ||
|
|
279
|
+
(this.dropdownPosition === 'auto' && !this.isListInViewportVertically)
|
|
280
|
+
)
|
|
281
|
+
},
|
|
282
|
+
|
|
283
|
+
newIconRight() {
|
|
284
|
+
if (this.clearable && this.newValue) {
|
|
285
|
+
return 'close-circle'
|
|
286
|
+
}
|
|
287
|
+
return this.iconRight
|
|
288
|
+
},
|
|
289
|
+
|
|
290
|
+
newIconRightClickable() {
|
|
291
|
+
if (this.clearable) {
|
|
292
|
+
return true
|
|
293
|
+
}
|
|
294
|
+
return this.iconRightClickable
|
|
295
|
+
},
|
|
296
|
+
|
|
297
|
+
contentStyle() {
|
|
298
|
+
return {
|
|
299
|
+
maxHeight: toCssWidth(this.maxHeight)
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
},
|
|
303
|
+
watch: {
|
|
304
|
+
/**
|
|
305
|
+
* When dropdown is toggled, check the visibility to know when
|
|
306
|
+
* to open upwards.
|
|
307
|
+
*/
|
|
308
|
+
isActive(active) {
|
|
309
|
+
if (this.dropdownPosition === 'auto') {
|
|
310
|
+
if (active) {
|
|
311
|
+
this.calcDropdownInViewportVertical()
|
|
312
|
+
} else {
|
|
313
|
+
// Timeout to wait for the animation to finish before recalculating
|
|
314
|
+
setTimeout(() => {
|
|
315
|
+
this.calcDropdownInViewportVertical()
|
|
316
|
+
}, 100)
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
},
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* When updating input's value
|
|
323
|
+
* 1. Emit changes
|
|
324
|
+
* 2. If value isn't the same as selected, set null
|
|
325
|
+
* 3. Close dropdown if value is clear or else open it
|
|
326
|
+
*/
|
|
327
|
+
newValue(value) {
|
|
328
|
+
this.$emit('input', value)
|
|
329
|
+
// Check if selected is invalid
|
|
330
|
+
const currentValue = this.getValue(this.selected)
|
|
331
|
+
if (currentValue && currentValue !== value) {
|
|
332
|
+
this.setSelected(null, false)
|
|
333
|
+
}
|
|
334
|
+
// Close dropdown if input is clear or else open it
|
|
335
|
+
if (this.hasFocus && (!this.openOnFocus || value)) {
|
|
336
|
+
this.isActive = !!value
|
|
337
|
+
}
|
|
338
|
+
},
|
|
339
|
+
|
|
340
|
+
/**
|
|
341
|
+
* When v-model is changed:
|
|
342
|
+
* 1. Update internal value.
|
|
343
|
+
* 2. If it's invalid, validate again.
|
|
344
|
+
*/
|
|
345
|
+
value(value) {
|
|
346
|
+
this.newValue = value
|
|
347
|
+
},
|
|
348
|
+
|
|
349
|
+
/**
|
|
350
|
+
* Select first option if "keep-first
|
|
351
|
+
*/
|
|
352
|
+
data() {
|
|
353
|
+
// Keep first option always pre-selected
|
|
354
|
+
if (this.keepFirst) {
|
|
355
|
+
this.$nextTick(() => {
|
|
356
|
+
if (this.isActive) {
|
|
357
|
+
this.selectFirstOption(this.computedData)
|
|
358
|
+
} else {
|
|
359
|
+
this.setHovered(null)
|
|
360
|
+
}
|
|
361
|
+
})
|
|
362
|
+
} else {
|
|
363
|
+
if (this.hovered) {
|
|
364
|
+
// reset hovered if list doesn't contain it
|
|
365
|
+
const hoveredValue = this.getValue(this.hovered)
|
|
366
|
+
const data = this.computedData.map((d) => d.items)
|
|
367
|
+
.reduce((a, b) => ([...a, ...b]), [])
|
|
368
|
+
if (!data.some((d) => this.getValue(d) === hoveredValue)) {
|
|
369
|
+
this.setHovered(null)
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
},
|
|
375
|
+
methods: {
|
|
376
|
+
/**
|
|
377
|
+
* Set which option is currently hovered.
|
|
378
|
+
*/
|
|
379
|
+
setHovered(option) {
|
|
380
|
+
if (option === undefined) return
|
|
381
|
+
|
|
382
|
+
this.hovered = option
|
|
383
|
+
},
|
|
384
|
+
|
|
385
|
+
/**
|
|
386
|
+
* Set which option is currently selected, update v-model,
|
|
387
|
+
* update input value and close dropdown.
|
|
388
|
+
*/
|
|
389
|
+
setSelected(option, closeDropdown = true, event = undefined) {
|
|
390
|
+
if (option === undefined) return
|
|
391
|
+
this.selected = option
|
|
392
|
+
this.$emit('select', this.selected, event)
|
|
393
|
+
if (this.selected !== null) {
|
|
394
|
+
if (this.clearOnSelect) {
|
|
395
|
+
const input = this.$refs.input
|
|
396
|
+
input.newValue = ''
|
|
397
|
+
input.$refs.input.value = ''
|
|
398
|
+
} else {
|
|
399
|
+
this.newValue = this.getValue(this.selected)
|
|
400
|
+
}
|
|
401
|
+
this.setHovered(null)
|
|
402
|
+
}
|
|
403
|
+
closeDropdown && this.$nextTick(() => {
|
|
404
|
+
this.isActive = false
|
|
405
|
+
})
|
|
406
|
+
this.checkValidity()
|
|
407
|
+
},
|
|
408
|
+
|
|
409
|
+
/**
|
|
410
|
+
* Select first option
|
|
411
|
+
*/
|
|
412
|
+
selectFirstOption(computedData) {
|
|
413
|
+
this.$nextTick(() => {
|
|
414
|
+
const nonEmptyElements = computedData.filter(
|
|
415
|
+
(element) => element.items && element.items.length
|
|
416
|
+
)
|
|
417
|
+
if (nonEmptyElements.length) {
|
|
418
|
+
const option = nonEmptyElements[0].items[0]
|
|
419
|
+
this.setHovered(option)
|
|
420
|
+
} else {
|
|
421
|
+
this.setHovered(null)
|
|
422
|
+
}
|
|
423
|
+
})
|
|
424
|
+
},
|
|
425
|
+
|
|
426
|
+
keydown(event) {
|
|
427
|
+
const { key } = event // cannot destructure preventDefault (https://stackoverflow.com/a/49616808/2774496)
|
|
428
|
+
// prevent emit submit event
|
|
429
|
+
if (key === 'Enter') event.preventDefault()
|
|
430
|
+
// Close dropdown on Tab & no hovered
|
|
431
|
+
if (key === 'Escape' || key === 'Tab') {
|
|
432
|
+
this.isActive = false
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
if (this.confirmKeys.indexOf(key) >= 0) {
|
|
436
|
+
// If adding by comma, don't add the comma to the input
|
|
437
|
+
if (key === ',') event.preventDefault()
|
|
438
|
+
// Close dropdown on select by Tab
|
|
439
|
+
const closeDropdown = !this.keepOpen || key === 'Tab'
|
|
440
|
+
if (this.hovered === null) {
|
|
441
|
+
// header and footer uses headerHovered && footerHovered. If header or footer
|
|
442
|
+
// was selected then fire event otherwise just return so a value isn't selected
|
|
443
|
+
this.checkIfHeaderOrFooterSelected(event, null, closeDropdown)
|
|
444
|
+
return
|
|
445
|
+
}
|
|
446
|
+
this.setSelected(this.hovered, closeDropdown, event)
|
|
447
|
+
}
|
|
448
|
+
},
|
|
449
|
+
|
|
450
|
+
selectHeaderOrFoterByClick(event, origin) {
|
|
451
|
+
this.checkIfHeaderOrFooterSelected(event, {origin: origin})
|
|
452
|
+
},
|
|
453
|
+
|
|
454
|
+
/**
|
|
455
|
+
* Check if header or footer was selected.
|
|
456
|
+
*/
|
|
457
|
+
checkIfHeaderOrFooterSelected(event, triggerClick, closeDropdown = true) {
|
|
458
|
+
if (this.selectableHeader && (this.headerHovered || (triggerClick && triggerClick.origin === 'header'))) {
|
|
459
|
+
this.$emit('select-header', event)
|
|
460
|
+
this.headerHovered = false
|
|
461
|
+
if (triggerClick) this.setHovered(null)
|
|
462
|
+
if (closeDropdown) this.isActive = false
|
|
463
|
+
}
|
|
464
|
+
if (this.selectableFooter && (this.footerHovered || (triggerClick && triggerClick.origin === 'footer'))) {
|
|
465
|
+
this.$emit('select-footer', event)
|
|
466
|
+
this.footerHovered = false
|
|
467
|
+
if (triggerClick) this.setHovered(null)
|
|
468
|
+
if (closeDropdown) this.isActive = false
|
|
469
|
+
}
|
|
470
|
+
},
|
|
471
|
+
|
|
472
|
+
/**
|
|
473
|
+
* Close dropdown if clicked outside.
|
|
474
|
+
*/
|
|
475
|
+
clickedOutside(event) {
|
|
476
|
+
const target = isCustomElement(this) ? event.composedPath()[0] : event.target
|
|
477
|
+
if (!this.hasFocus && this.whiteList.indexOf(target) < 0) {
|
|
478
|
+
if (this.keepFirst && this.hovered && this.selectOnClickOutside) {
|
|
479
|
+
this.setSelected(this.hovered, true)
|
|
480
|
+
} else {
|
|
481
|
+
this.isActive = false
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
},
|
|
485
|
+
|
|
486
|
+
/**
|
|
487
|
+
* Return display text for the input.
|
|
488
|
+
* If object, get value from path, or else just the value.
|
|
489
|
+
*/
|
|
490
|
+
getValue(option) {
|
|
491
|
+
if (option === null) return
|
|
492
|
+
|
|
493
|
+
if (typeof this.customFormatter !== 'undefined') {
|
|
494
|
+
return this.customFormatter(option)
|
|
495
|
+
}
|
|
496
|
+
return typeof option === 'object' ? getValueByPath(option, this.field) : option
|
|
497
|
+
},
|
|
498
|
+
|
|
499
|
+
/**
|
|
500
|
+
* Check if the scroll list inside the dropdown
|
|
501
|
+
* reached it's end.
|
|
502
|
+
*/
|
|
503
|
+
checkIfReachedTheEndOfScroll(list) {
|
|
504
|
+
if (list.clientHeight !== list.scrollHeight &&
|
|
505
|
+
list.scrollTop + list.clientHeight >= list.scrollHeight
|
|
506
|
+
) {
|
|
507
|
+
this.$emit('infinite-scroll')
|
|
508
|
+
}
|
|
509
|
+
},
|
|
510
|
+
|
|
511
|
+
/**
|
|
512
|
+
* Calculate if the dropdown is vertically visible when activated,
|
|
513
|
+
* otherwise it is openened upwards.
|
|
514
|
+
*/
|
|
515
|
+
calcDropdownInViewportVertical() {
|
|
516
|
+
this.$nextTick(() => {
|
|
517
|
+
/**
|
|
518
|
+
* this.$refs.dropdown may be undefined
|
|
519
|
+
* when Autocomplete is conditional rendered
|
|
520
|
+
*/
|
|
521
|
+
if (this.$refs.dropdown === undefined) return
|
|
522
|
+
|
|
523
|
+
const rect = this.$refs.dropdown.getBoundingClientRect()
|
|
524
|
+
|
|
525
|
+
this.isListInViewportVertically = rect.top >= 0 &&
|
|
526
|
+
rect.bottom <= (window.innerHeight || document.documentElement.clientHeight)
|
|
527
|
+
if (this.appendToBody) {
|
|
528
|
+
this.updateAppendToBody()
|
|
529
|
+
}
|
|
530
|
+
})
|
|
531
|
+
},
|
|
532
|
+
|
|
533
|
+
/**
|
|
534
|
+
* Arrows keys listener.
|
|
535
|
+
* If dropdown is active, set hovered option, or else just open.
|
|
536
|
+
*/
|
|
537
|
+
keyArrows(direction) {
|
|
538
|
+
const sum = direction === 'down' ? 1 : -1
|
|
539
|
+
if (this.isActive) {
|
|
540
|
+
const data = this.computedData.map(
|
|
541
|
+
(d) => d.items).reduce((a, b) => ([...a, ...b]), [])
|
|
542
|
+
if (this.hasHeaderSlot && this.selectableHeader) {
|
|
543
|
+
data.unshift(undefined)
|
|
544
|
+
}
|
|
545
|
+
if (this.hasFooterSlot && this.selectableFooter) {
|
|
546
|
+
data.push(undefined)
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
let index
|
|
550
|
+
if (this.headerHovered) {
|
|
551
|
+
index = 0 + sum
|
|
552
|
+
} else if (this.footerHovered) {
|
|
553
|
+
index = (data.length - 1) + sum
|
|
554
|
+
} else {
|
|
555
|
+
index = data.indexOf(this.hovered) + sum
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
index = index > data.length - 1 ? data.length - 1 : index
|
|
559
|
+
index = index < 0 ? 0 : index
|
|
560
|
+
|
|
561
|
+
this.footerHovered = false
|
|
562
|
+
this.headerHovered = false
|
|
563
|
+
this.setHovered(data[index] !== undefined ? data[index] : null)
|
|
564
|
+
if (this.hasFooterSlot && this.selectableFooter && index === data.length - 1) {
|
|
565
|
+
this.footerHovered = true
|
|
566
|
+
}
|
|
567
|
+
if (this.hasHeaderSlot && this.selectableHeader && index === 0) {
|
|
568
|
+
this.headerHovered = true
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
const list = this.$refs.dropdown.querySelector('.dropdown-content')
|
|
572
|
+
let querySelectorText = 'a.dropdown-item:not(.is-disabled)'
|
|
573
|
+
if (this.hasHeaderSlot && this.selectableHeader) {
|
|
574
|
+
querySelectorText += ',div.dropdown-header'
|
|
575
|
+
}
|
|
576
|
+
if (this.hasFooterSlot && this.selectableFooter) {
|
|
577
|
+
querySelectorText += ',div.dropdown-footer'
|
|
578
|
+
}
|
|
579
|
+
const element = list.querySelectorAll(querySelectorText)[index]
|
|
580
|
+
|
|
581
|
+
if (!element) return
|
|
582
|
+
|
|
583
|
+
const visMin = list.scrollTop
|
|
584
|
+
const visMax = list.scrollTop + list.clientHeight - element.clientHeight
|
|
585
|
+
|
|
586
|
+
if (element.offsetTop < visMin) {
|
|
587
|
+
list.scrollTop = element.offsetTop
|
|
588
|
+
} else if (element.offsetTop >= visMax) {
|
|
589
|
+
list.scrollTop = element.offsetTop - list.clientHeight + element.clientHeight
|
|
590
|
+
}
|
|
591
|
+
} else {
|
|
592
|
+
this.isActive = true
|
|
593
|
+
}
|
|
594
|
+
},
|
|
595
|
+
|
|
596
|
+
/**
|
|
597
|
+
* Focus listener.
|
|
598
|
+
* If value is the same as selected, select all text.
|
|
599
|
+
*/
|
|
600
|
+
focused(event) {
|
|
601
|
+
if (this.getValue(this.selected) === this.newValue) {
|
|
602
|
+
this.$el.querySelector('input').select()
|
|
603
|
+
}
|
|
604
|
+
if (this.openOnFocus) {
|
|
605
|
+
this.isActive = true
|
|
606
|
+
if (this.keepFirst) {
|
|
607
|
+
// If open on focus, update the hovered
|
|
608
|
+
this.selectFirstOption(this.computedData)
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
this.hasFocus = true
|
|
612
|
+
this.$emit('focus', event)
|
|
613
|
+
},
|
|
614
|
+
|
|
615
|
+
/**
|
|
616
|
+
* Blur listener.
|
|
617
|
+
*/
|
|
618
|
+
onBlur(event) {
|
|
619
|
+
this.hasFocus = false
|
|
620
|
+
this.$emit('blur', event)
|
|
621
|
+
},
|
|
622
|
+
onInput() {
|
|
623
|
+
const currentValue = this.getValue(this.selected)
|
|
624
|
+
if (currentValue && currentValue === this.newValue) return
|
|
625
|
+
this.$emit('typing', this.newValue)
|
|
626
|
+
this.checkValidity()
|
|
627
|
+
},
|
|
628
|
+
rightIconClick(event) {
|
|
629
|
+
if (this.clearable) {
|
|
630
|
+
this.newValue = ''
|
|
631
|
+
this.setSelected(null, false)
|
|
632
|
+
if (this.openOnFocus) {
|
|
633
|
+
this.$refs.input.$el.focus()
|
|
634
|
+
}
|
|
635
|
+
} else {
|
|
636
|
+
this.$emit('icon-right-click', event)
|
|
637
|
+
}
|
|
638
|
+
},
|
|
639
|
+
checkValidity() {
|
|
640
|
+
if (this.useHtml5Validation) {
|
|
641
|
+
this.$nextTick(() => {
|
|
642
|
+
this.checkHtml5Validity()
|
|
643
|
+
})
|
|
644
|
+
}
|
|
645
|
+
},
|
|
646
|
+
updateAppendToBody() {
|
|
647
|
+
const dropdownMenu = this.$refs.dropdown
|
|
648
|
+
const trigger = this.$refs.input.$el
|
|
649
|
+
if (dropdownMenu && trigger) {
|
|
650
|
+
// update wrapper dropdown
|
|
651
|
+
const root = this.$data._bodyEl
|
|
652
|
+
root.classList.forEach((item) => root.classList.remove(item))
|
|
653
|
+
root.classList.add('autocomplete')
|
|
654
|
+
root.classList.add('control')
|
|
655
|
+
if (this.expandend) {
|
|
656
|
+
root.classList.add('is-expandend')
|
|
657
|
+
}
|
|
658
|
+
const rect = trigger.getBoundingClientRect()
|
|
659
|
+
let top = rect.top + window.scrollY
|
|
660
|
+
let left = rect.left + window.scrollX
|
|
661
|
+
if (!this.isOpenedTop) {
|
|
662
|
+
top += trigger.clientHeight
|
|
663
|
+
} else {
|
|
664
|
+
top -= dropdownMenu.clientHeight
|
|
665
|
+
}
|
|
666
|
+
this.style = {
|
|
667
|
+
position: 'absolute',
|
|
668
|
+
top: `${top}px`,
|
|
669
|
+
left: `${left}px`,
|
|
670
|
+
width: `${trigger.clientWidth}px`,
|
|
671
|
+
maxWidth: `${trigger.clientWidth}px`,
|
|
672
|
+
zIndex: '99'
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
},
|
|
677
|
+
created() {
|
|
678
|
+
if (typeof window !== 'undefined') {
|
|
679
|
+
document.addEventListener('click', this.clickedOutside)
|
|
680
|
+
if (this.dropdownPosition === 'auto') { window.addEventListener('resize', this.calcDropdownInViewportVertical) }
|
|
681
|
+
}
|
|
682
|
+
},
|
|
683
|
+
mounted() {
|
|
684
|
+
if (this.checkInfiniteScroll &&
|
|
685
|
+
this.$refs.dropdown && this.$refs.dropdown.querySelector('.dropdown-content')
|
|
686
|
+
) {
|
|
687
|
+
const list = this.$refs.dropdown.querySelector('.dropdown-content')
|
|
688
|
+
list.addEventListener('scroll', () => this.checkIfReachedTheEndOfScroll(list))
|
|
689
|
+
}
|
|
690
|
+
if (this.appendToBody) {
|
|
691
|
+
this.$data._bodyEl = createAbsoluteElement(this.$refs.dropdown)
|
|
692
|
+
this.updateAppendToBody()
|
|
693
|
+
}
|
|
694
|
+
},
|
|
695
|
+
beforeDestroy() {
|
|
696
|
+
if (typeof window !== 'undefined') {
|
|
697
|
+
document.removeEventListener('click', this.clickedOutside)
|
|
698
|
+
if (this.dropdownPosition === 'auto') { window.removeEventListener('resize', this.calcDropdownInViewportVertical) }
|
|
699
|
+
}
|
|
700
|
+
if (this.checkInfiniteScroll &&
|
|
701
|
+
this.$refs.dropdown && this.$refs.dropdown.querySelector('.dropdown-content')
|
|
702
|
+
) {
|
|
703
|
+
const list = this.$refs.dropdown.querySelector('.dropdown-content')
|
|
704
|
+
list.removeEventListener('scroll', this.checkIfReachedTheEndOfScroll)
|
|
705
|
+
}
|
|
706
|
+
if (this.appendToBody) {
|
|
707
|
+
removeElement(this.$data._bodyEl)
|
|
708
|
+
}
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
</script>
|