q2-tecton-elements 1.11.4 → 1.12.1
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/cjs/{index-f5807a6a.js → index-773c3eec.js} +13 -11
- package/dist/cjs/loader.cjs.js +1 -1
- package/dist/cjs/q2-btn_2.cjs.entry.js +2 -2
- package/dist/cjs/q2-calendar.cjs.entry.js +12 -2
- package/dist/cjs/q2-card.cjs.entry.js +1 -1
- package/dist/cjs/q2-carousel-pane.cjs.entry.js +1 -1
- package/dist/cjs/q2-carousel.cjs.entry.js +1 -1
- package/dist/cjs/q2-checkbox-group.cjs.entry.js +1 -1
- package/dist/cjs/q2-checkbox.cjs.entry.js +4 -3
- package/dist/cjs/q2-dropdown-item.cjs.entry.js +1 -1
- package/dist/cjs/q2-dropdown.cjs.entry.js +1 -1
- package/dist/cjs/q2-editable-field.cjs.entry.js +1 -1
- package/dist/cjs/q2-icon.cjs.entry.js +1 -1
- package/dist/cjs/q2-input.cjs.entry.js +4 -4
- package/dist/cjs/q2-loc.cjs.entry.js +1 -1
- package/dist/cjs/q2-message.cjs.entry.js +1 -1
- package/dist/cjs/q2-optgroup.cjs.entry.js +1 -1
- package/dist/cjs/q2-option-list.cjs.entry.js +357 -0
- package/dist/cjs/q2-option.cjs.entry.js +2 -10
- package/dist/cjs/q2-pagination.cjs.entry.js +1 -1
- package/dist/cjs/q2-pill.cjs.entry.js +137 -0
- package/dist/cjs/q2-radio-group.cjs.entry.js +1 -1
- package/dist/cjs/q2-radio.cjs.entry.js +1 -1
- package/dist/cjs/q2-section.cjs.entry.js +1 -1
- package/dist/cjs/q2-select.cjs.entry.js +15 -6
- package/dist/cjs/q2-stepper-pane.cjs.entry.js +1 -1
- package/dist/cjs/q2-stepper.cjs.entry.js +2 -2
- package/dist/cjs/q2-tab-container.cjs.entry.js +5 -1
- package/dist/cjs/q2-tag.cjs.entry.js +94 -0
- package/dist/cjs/q2-tecton-elements.cjs.js +1 -1
- package/dist/cjs/q2-textarea.cjs.entry.js +1 -1
- package/dist/collection/collection-manifest.json +3 -0
- package/dist/collection/components/q2-btn/styles.css +1 -1
- package/dist/collection/components/q2-calendar/helpers.js +6 -0
- package/dist/collection/components/q2-calendar/index.js +6 -2
- package/dist/collection/components/q2-checkbox/index.js +3 -2
- package/dist/collection/components/q2-input/index.js +4 -3
- package/dist/collection/components/q2-input/styles.css +9 -2
- package/dist/collection/components/q2-option/index.js +19 -25
- package/dist/collection/components/q2-option/styles.css +5 -0
- package/dist/collection/components/q2-option-list/index.js +646 -0
- package/dist/collection/components/q2-option-list/styles.css +128 -0
- package/dist/collection/components/q2-pill/index.js +324 -0
- package/dist/collection/components/q2-pill/styles.css +227 -0
- package/dist/collection/components/q2-select/index.js +14 -5
- package/dist/collection/components/q2-stepper/styles.css +1 -1
- package/dist/collection/components/q2-tab-container/index.js +4 -0
- package/dist/collection/components/q2-tag/index.js +200 -0
- package/dist/collection/components/q2-tag/styles.css +141 -0
- package/dist/collection/utils/index.js +13 -11
- package/dist/esm/{index-0e13a57f.js → index-fa32f694.js} +13 -11
- package/dist/esm/loader.js +1 -1
- package/dist/esm/q2-btn_2.entry.js +2 -2
- package/dist/esm/q2-calendar.entry.js +12 -2
- package/dist/esm/q2-card.entry.js +1 -1
- package/dist/esm/q2-carousel-pane.entry.js +1 -1
- package/dist/esm/q2-carousel.entry.js +1 -1
- package/dist/esm/q2-checkbox-group.entry.js +1 -1
- package/dist/esm/q2-checkbox.entry.js +4 -3
- package/dist/esm/q2-dropdown-item.entry.js +1 -1
- package/dist/esm/q2-dropdown.entry.js +1 -1
- package/dist/esm/q2-editable-field.entry.js +1 -1
- package/dist/esm/q2-icon.entry.js +1 -1
- package/dist/esm/q2-input.entry.js +4 -4
- package/dist/esm/q2-loc.entry.js +1 -1
- package/dist/esm/q2-message.entry.js +1 -1
- package/dist/esm/q2-optgroup.entry.js +1 -1
- package/dist/esm/q2-option-list.entry.js +353 -0
- package/dist/esm/q2-option.entry.js +3 -11
- package/dist/esm/q2-pagination.entry.js +1 -1
- package/dist/esm/q2-pill.entry.js +133 -0
- package/dist/esm/q2-radio-group.entry.js +1 -1
- package/dist/esm/q2-radio.entry.js +1 -1
- package/dist/esm/q2-section.entry.js +1 -1
- package/dist/esm/q2-select.entry.js +15 -6
- package/dist/esm/q2-stepper-pane.entry.js +1 -1
- package/dist/esm/q2-stepper.entry.js +2 -2
- package/dist/esm/q2-tab-container.entry.js +5 -1
- package/dist/esm/q2-tag.entry.js +90 -0
- package/dist/esm/q2-tecton-elements.js +1 -1
- package/dist/esm/q2-textarea.entry.js +1 -1
- package/dist/q2-tecton-elements/{p-ca847db7.entry.js → p-08668234.entry.js} +1 -1
- package/dist/q2-tecton-elements/{p-2be33492.entry.js → p-0a7cff38.entry.js} +1 -1
- package/dist/q2-tecton-elements/p-167a19fd.entry.js +1 -0
- package/dist/q2-tecton-elements/{p-a72e7a12.entry.js → p-2afdc922.entry.js} +1 -1
- package/dist/q2-tecton-elements/{p-fe61c1aa.entry.js → p-30bf5f44.entry.js} +1 -1
- package/dist/q2-tecton-elements/{p-f85bf7fb.entry.js → p-34415315.entry.js} +1 -1
- package/dist/q2-tecton-elements/{p-3479847c.entry.js → p-54300d2f.entry.js} +1 -1
- package/dist/q2-tecton-elements/p-54f0d64e.entry.js +1 -0
- package/dist/q2-tecton-elements/p-5b906cf1.entry.js +1 -0
- package/dist/q2-tecton-elements/p-5effd81a.entry.js +1 -0
- package/dist/q2-tecton-elements/{p-27ec0a16.entry.js → p-7ce98c1a.entry.js} +1 -1
- package/dist/q2-tecton-elements/{p-346b65d5.entry.js → p-91dba21f.entry.js} +1 -1
- package/dist/q2-tecton-elements/{p-2372f988.entry.js → p-9a3c37ab.entry.js} +1 -1
- package/dist/q2-tecton-elements/{p-c83dba0a.entry.js → p-a0248299.entry.js} +1 -1
- package/dist/q2-tecton-elements/{p-f435dc7e.entry.js → p-aca8302b.entry.js} +1 -1
- package/dist/q2-tecton-elements/{p-bfd77f9b.entry.js → p-b9c2c1d3.entry.js} +1 -1
- package/dist/q2-tecton-elements/{p-f85da2a8.js → p-c3d68d5c.js} +1 -1
- package/dist/q2-tecton-elements/{p-841ec108.entry.js → p-c460e5ed.entry.js} +1 -1
- package/dist/q2-tecton-elements/{p-88bc2f49.entry.js → p-c5199147.entry.js} +1 -1
- package/dist/q2-tecton-elements/{p-492dfb55.entry.js → p-c5e6f7fa.entry.js} +1 -1
- package/dist/q2-tecton-elements/{p-9ccbc3d8.entry.js → p-d3058002.entry.js} +1 -1
- package/dist/q2-tecton-elements/{p-fc318ae2.entry.js → p-d65aaed2.entry.js} +1 -1
- package/dist/q2-tecton-elements/{p-701b381a.entry.js → p-d9bc6494.entry.js} +1 -1
- package/dist/q2-tecton-elements/p-df86f160.entry.js +1 -0
- package/dist/q2-tecton-elements/{p-f73df612.entry.js → p-e38080d2.entry.js} +1 -1
- package/dist/q2-tecton-elements/p-e9d69ba8.entry.js +1 -0
- package/dist/q2-tecton-elements/{p-d199fca8.entry.js → p-f98dc161.entry.js} +1 -1
- package/dist/q2-tecton-elements/{p-6a83a97c.entry.js → p-fa9e3825.entry.js} +1 -1
- package/dist/q2-tecton-elements/{p-b5b12e46.entry.js → p-fe6407a4.entry.js} +1 -1
- package/dist/q2-tecton-elements/q2-tecton-elements.esm.js +1 -1
- package/dist/test/elements/q2-tag-test.js +151 -0
- package/dist/test/helpers.js +7 -0
- package/dist/types/components/q2-calendar/helpers.d.ts +1 -0
- package/dist/types/components/q2-checkbox/index.d.ts +1 -1
- package/dist/types/components/q2-option/index.d.ts +2 -3
- package/dist/types/components/q2-option-list/index.d.ts +62 -0
- package/dist/types/components/q2-pill/index.d.ts +39 -0
- package/dist/types/components/q2-tag/index.d.ts +28 -0
- package/dist/types/components.d.ts +95 -1
- package/dist/types/workspace/workspace/tecton-production_release_1.12.x/packages/q2-tecton-elements/.stencil/test/elements/q2-tag-test.d.ts +1 -0
- package/dist/types/workspace/workspace/{tecton-production_release_1.11.x → tecton-production_release_1.12.x}/packages/q2-tecton-elements/.stencil/test/helpers.d.ts +1 -0
- package/package.json +2 -2
- package/dist/q2-tecton-elements/p-564154f3.entry.js +0 -1
- package/dist/q2-tecton-elements/p-6702eb4d.entry.js +0 -1
- package/dist/q2-tecton-elements/p-dffbcec3.entry.js +0 -1
|
@@ -0,0 +1,646 @@
|
|
|
1
|
+
import { Component, Prop, h, Event, State, Element, Host, Method, Watch, Listen } from '@stencil/core';
|
|
2
|
+
import { isEventFromElement, overrideFocus } from 'src/utils';
|
|
3
|
+
export class Q2OptionList {
|
|
4
|
+
constructor() {
|
|
5
|
+
this.role = 'listbox';
|
|
6
|
+
this.direction = 'down';
|
|
7
|
+
this.selectedOptions = [];
|
|
8
|
+
this.scheduledAfterRender = [];
|
|
9
|
+
/// Event Handlers ///
|
|
10
|
+
this.keydownHandler = (event, ignoreSelectionEvents) => {
|
|
11
|
+
event.stopPropagation();
|
|
12
|
+
const { activeIndex, customSearch, allOptions } = this;
|
|
13
|
+
const { key, shiftKey } = event;
|
|
14
|
+
let newOption;
|
|
15
|
+
switch (key) {
|
|
16
|
+
case ' ':
|
|
17
|
+
case 'Enter':
|
|
18
|
+
if (ignoreSelectionEvents) {
|
|
19
|
+
this.setDefaultActiveElement();
|
|
20
|
+
break;
|
|
21
|
+
}
|
|
22
|
+
event.preventDefault();
|
|
23
|
+
newOption = allOptions.find(element => element.active);
|
|
24
|
+
if (!newOption || newOption.disabled)
|
|
25
|
+
break;
|
|
26
|
+
this.selectOption(newOption.value);
|
|
27
|
+
break;
|
|
28
|
+
case 'ArrowUp':
|
|
29
|
+
event.preventDefault();
|
|
30
|
+
const isFirstOption = activeIndex === 0;
|
|
31
|
+
if (isFirstOption)
|
|
32
|
+
break;
|
|
33
|
+
if (activeIndex === undefined) {
|
|
34
|
+
this.setDefaultActiveElement();
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
const nextIndex = this.getNextVisibleIndex(-1);
|
|
38
|
+
if (nextIndex === -1)
|
|
39
|
+
break;
|
|
40
|
+
this.adjustActiveOptionAndScroll(nextIndex - activeIndex);
|
|
41
|
+
}
|
|
42
|
+
break;
|
|
43
|
+
case 'ArrowDown':
|
|
44
|
+
event.preventDefault();
|
|
45
|
+
const isLastOption = activeIndex === allOptions.length - 1;
|
|
46
|
+
if (isLastOption)
|
|
47
|
+
break;
|
|
48
|
+
if (activeIndex === undefined) {
|
|
49
|
+
this.setDefaultActiveElement();
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
const nextIndex = this.getNextVisibleIndex(1);
|
|
53
|
+
if (nextIndex === -1)
|
|
54
|
+
break;
|
|
55
|
+
this.adjustActiveOptionAndScroll(nextIndex - activeIndex);
|
|
56
|
+
}
|
|
57
|
+
break;
|
|
58
|
+
case 'Home':
|
|
59
|
+
event.preventDefault();
|
|
60
|
+
this.openDropdownWithActiveElement(0);
|
|
61
|
+
break;
|
|
62
|
+
case 'End':
|
|
63
|
+
event.preventDefault();
|
|
64
|
+
this.openDropdownWithActiveElement(allOptions.length - 1);
|
|
65
|
+
break;
|
|
66
|
+
case 'PageUp':
|
|
67
|
+
event.preventDefault();
|
|
68
|
+
this.openDropdownWithActiveElement(Math.max(activeIndex - 10, 0));
|
|
69
|
+
break;
|
|
70
|
+
case 'PageDown':
|
|
71
|
+
event.preventDefault();
|
|
72
|
+
this.openDropdownWithActiveElement(Math.min(activeIndex + 10, allOptions.length - 1));
|
|
73
|
+
break;
|
|
74
|
+
case 'Tab':
|
|
75
|
+
if (ignoreSelectionEvents)
|
|
76
|
+
break;
|
|
77
|
+
if (shiftKey)
|
|
78
|
+
break;
|
|
79
|
+
newOption = allOptions.find(element => element.active);
|
|
80
|
+
if (!newOption || newOption.disabled)
|
|
81
|
+
return;
|
|
82
|
+
this.selectOption(newOption.value);
|
|
83
|
+
break;
|
|
84
|
+
case 'Esc':
|
|
85
|
+
case 'Escape':
|
|
86
|
+
if (this.noSelect)
|
|
87
|
+
this.setActiveElement(null);
|
|
88
|
+
this.open = false;
|
|
89
|
+
break;
|
|
90
|
+
default:
|
|
91
|
+
if (customSearch)
|
|
92
|
+
break;
|
|
93
|
+
if (!key.match(/^[A-Za-z0-9]$/))
|
|
94
|
+
break;
|
|
95
|
+
// search in non-searchable select: alpha-numeric only
|
|
96
|
+
this.searchAndFocus(key);
|
|
97
|
+
break;
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
this.focusoutHandler = (event) => {
|
|
101
|
+
const { relatedTarget } = event;
|
|
102
|
+
const isInDropdown = this.allOptions.includes(relatedTarget);
|
|
103
|
+
const isInLightDom = !isInDropdown && this.hostElement.contains(relatedTarget);
|
|
104
|
+
if (isInDropdown || isInLightDom) {
|
|
105
|
+
event.stopPropagation();
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
this.clickHandler = (event) => {
|
|
109
|
+
const target = event.target;
|
|
110
|
+
if (target.localName !== 'q2-option' || target.disabled) {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
this.selectOption(target.value);
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
/// LifeCycle Hooks ///
|
|
117
|
+
componentWillLoad() {
|
|
118
|
+
this.hasOptions = !!this.hostElement.querySelectorAll('q2-option').length;
|
|
119
|
+
}
|
|
120
|
+
componentDidLoad() {
|
|
121
|
+
overrideFocus(this.hostElement);
|
|
122
|
+
this.checkOptions();
|
|
123
|
+
}
|
|
124
|
+
componentDidRender() {
|
|
125
|
+
this.scheduledAfterRender.forEach(fn => fn());
|
|
126
|
+
this.scheduledAfterRender = [];
|
|
127
|
+
}
|
|
128
|
+
/// Getters ///
|
|
129
|
+
get allOptions() {
|
|
130
|
+
return this.getRootSlot(this.hostElement);
|
|
131
|
+
}
|
|
132
|
+
/// Helpers ///
|
|
133
|
+
checkOptions() {
|
|
134
|
+
const { noSelect, type, allOptions } = this;
|
|
135
|
+
if (!noSelect && !type)
|
|
136
|
+
return;
|
|
137
|
+
const optionRole = type === 'menu' ? 'menuitem' : 'option';
|
|
138
|
+
allOptions.forEach(option => {
|
|
139
|
+
if (noSelect)
|
|
140
|
+
option.noSelect = true;
|
|
141
|
+
if (type)
|
|
142
|
+
option.role = optionRole;
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
getRootSlot(element) {
|
|
146
|
+
var _a;
|
|
147
|
+
const slot = element.querySelector('slot');
|
|
148
|
+
const assignedElements = (_a = slot === null || slot === void 0 ? void 0 : slot.assignedElements()) !== null && _a !== void 0 ? _a : Array.from(element.children);
|
|
149
|
+
const hasAnotherSlot = !!assignedElements.length && assignedElements[0].tagName === 'SLOT';
|
|
150
|
+
if (hasAnotherSlot) {
|
|
151
|
+
return this.getRootSlot(assignedElements[0]);
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
return assignedElements;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
scrollToActiveOption() {
|
|
158
|
+
const activeOption = this.allOptions[this.activeIndex];
|
|
159
|
+
activeOption === null || activeOption === void 0 ? void 0 : activeOption.scrollIntoView({ block: 'nearest' });
|
|
160
|
+
}
|
|
161
|
+
resizeIframe() {
|
|
162
|
+
var _a, _b;
|
|
163
|
+
return (_b = (_a = window.TectonElements) === null || _a === void 0 ? void 0 : _a.resizeIframe) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
164
|
+
}
|
|
165
|
+
openDropdownWithActiveElement(activeIndex) {
|
|
166
|
+
if (this.disabled)
|
|
167
|
+
return;
|
|
168
|
+
this.activeIndex = activeIndex;
|
|
169
|
+
this.open = true;
|
|
170
|
+
this.setActiveOption();
|
|
171
|
+
this.setFocusedOption();
|
|
172
|
+
this.scheduledAfterRender.push(() => {
|
|
173
|
+
this.scrollToActiveOption();
|
|
174
|
+
this.resizeIframe();
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
getDefaultActiveIndex() {
|
|
178
|
+
const { allOptions } = this;
|
|
179
|
+
const firstSelected = allOptions.findIndex(element => element.selected);
|
|
180
|
+
if (firstSelected > -1)
|
|
181
|
+
return firstSelected;
|
|
182
|
+
const firstEnabled = allOptions.findIndex(element => !element.hidden);
|
|
183
|
+
if (firstEnabled > -1)
|
|
184
|
+
return firstEnabled;
|
|
185
|
+
return 0;
|
|
186
|
+
}
|
|
187
|
+
updateSingleOptionAttrs() {
|
|
188
|
+
var _a, _b;
|
|
189
|
+
const { allOptions, selectedOptions } = this;
|
|
190
|
+
const singleValue = (_b = (_a = selectedOptions[0]) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : undefined;
|
|
191
|
+
allOptions.forEach(element => {
|
|
192
|
+
element.selected = element.value === singleValue;
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
updateMultipleOptionAttrs() {
|
|
196
|
+
const { allOptions, selectedOptions } = this;
|
|
197
|
+
const selectedValues = selectedOptions.map(option => option.value);
|
|
198
|
+
allOptions.forEach(element => {
|
|
199
|
+
element.selected = selectedValues.includes(element.value);
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
setActiveOption() {
|
|
203
|
+
if (!this.open)
|
|
204
|
+
return;
|
|
205
|
+
const activeIndex = this.activeIndex;
|
|
206
|
+
this.allOptions.forEach((element, elementIndex) => {
|
|
207
|
+
element.active = activeIndex === elementIndex;
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
setFocusedOption() {
|
|
211
|
+
const option = this.allOptions[this.activeIndex];
|
|
212
|
+
if (!option)
|
|
213
|
+
return;
|
|
214
|
+
setTimeout(() => {
|
|
215
|
+
option.focus();
|
|
216
|
+
}, 25);
|
|
217
|
+
}
|
|
218
|
+
getNextVisibleIndex(direction) {
|
|
219
|
+
let index = this.activeIndex + direction;
|
|
220
|
+
while (index >= 0 && index <= this.allOptions.length - 1) {
|
|
221
|
+
const { display, visibility } = window.getComputedStyle(this.allOptions[index]);
|
|
222
|
+
if (display !== 'none' && visibility !== 'hidden') {
|
|
223
|
+
return index;
|
|
224
|
+
}
|
|
225
|
+
index = index + direction;
|
|
226
|
+
}
|
|
227
|
+
return -1;
|
|
228
|
+
}
|
|
229
|
+
selectOption(selectedValue) {
|
|
230
|
+
const option = this.allOptions.find(({ value }) => value === selectedValue);
|
|
231
|
+
const valueObject = {
|
|
232
|
+
value: selectedValue,
|
|
233
|
+
display: option.display || option.innerText.trim()
|
|
234
|
+
};
|
|
235
|
+
const { multiple, noSelect } = this;
|
|
236
|
+
let values;
|
|
237
|
+
if (multiple) {
|
|
238
|
+
const { selectedOptions = [] } = this;
|
|
239
|
+
const isAlreadySelected = !!selectedOptions.find(({ value }) => value === selectedValue);
|
|
240
|
+
if (isAlreadySelected) {
|
|
241
|
+
values = selectedOptions.filter(({ value }) => value !== selectedValue);
|
|
242
|
+
}
|
|
243
|
+
else {
|
|
244
|
+
values = [...selectedOptions, valueObject];
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
else {
|
|
248
|
+
values = [valueObject];
|
|
249
|
+
}
|
|
250
|
+
if (noSelect)
|
|
251
|
+
this.setActiveElement(null);
|
|
252
|
+
else
|
|
253
|
+
this.selectedOptions = values;
|
|
254
|
+
this.change.emit({ value: selectedValue, values });
|
|
255
|
+
if (multiple)
|
|
256
|
+
return;
|
|
257
|
+
this.open = false;
|
|
258
|
+
}
|
|
259
|
+
adjustActiveOptionAndScroll(numToAdd) {
|
|
260
|
+
this.activeIndex += numToAdd;
|
|
261
|
+
this.setActiveOption();
|
|
262
|
+
this.setFocusedOption();
|
|
263
|
+
this.scrollToActiveOption();
|
|
264
|
+
}
|
|
265
|
+
resetTimer() {
|
|
266
|
+
if (this.searchStringTimer) {
|
|
267
|
+
clearTimeout(this.searchStringTimer);
|
|
268
|
+
}
|
|
269
|
+
this.searchStringTimer = window.setTimeout(() => {
|
|
270
|
+
this.searchString = null;
|
|
271
|
+
}, 2000);
|
|
272
|
+
}
|
|
273
|
+
searchAndFocus(key) {
|
|
274
|
+
this.resetTimer();
|
|
275
|
+
let searchString = this.searchString ? `${this.searchString}${key}` : key;
|
|
276
|
+
searchString = searchString.replace(/[^0-9a-z]/gi, '');
|
|
277
|
+
this.searchString = searchString;
|
|
278
|
+
const searchRegEx = new RegExp(searchString, 'i');
|
|
279
|
+
const foundIndex = this.allOptions.findIndex(option => option.value === searchString || option.textContent.match(searchRegEx));
|
|
280
|
+
if (foundIndex === -1)
|
|
281
|
+
return;
|
|
282
|
+
this.setActiveElement(foundIndex);
|
|
283
|
+
}
|
|
284
|
+
/// Watchers ///
|
|
285
|
+
selectedOptionsUpdated() {
|
|
286
|
+
if (this.multiple) {
|
|
287
|
+
this.updateMultipleOptionAttrs();
|
|
288
|
+
}
|
|
289
|
+
else {
|
|
290
|
+
this.updateSingleOptionAttrs();
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
openChanged(newValue) {
|
|
294
|
+
this.optionListState.emit({ open: newValue });
|
|
295
|
+
}
|
|
296
|
+
/// Listeners ///
|
|
297
|
+
delegateFocus(event) {
|
|
298
|
+
if (!isEventFromElement(event, this.hostElement))
|
|
299
|
+
return;
|
|
300
|
+
this.open = true;
|
|
301
|
+
this.setDefaultActiveElement();
|
|
302
|
+
}
|
|
303
|
+
handleClick(event) {
|
|
304
|
+
event.stopPropagation();
|
|
305
|
+
}
|
|
306
|
+
/// Public Methods ///
|
|
307
|
+
toggle() {
|
|
308
|
+
const isOpen = !this.open;
|
|
309
|
+
this.open = isOpen;
|
|
310
|
+
}
|
|
311
|
+
setDefaultActiveElement() {
|
|
312
|
+
this.activeIndex = this.getDefaultActiveIndex();
|
|
313
|
+
this.setActiveOption();
|
|
314
|
+
this.setFocusedOption();
|
|
315
|
+
}
|
|
316
|
+
setActiveElement(index) {
|
|
317
|
+
this.activeIndex = index;
|
|
318
|
+
this.setActiveOption();
|
|
319
|
+
this.setFocusedOption();
|
|
320
|
+
}
|
|
321
|
+
handleExternalKeydown(event) {
|
|
322
|
+
const keysThatTriggerOpen = ['ArrowDown', 'ArrowUp', 'PageDown', 'PageUp', 'Home', 'End'];
|
|
323
|
+
if (keysThatTriggerOpen.includes(event.key)) {
|
|
324
|
+
this.open = true;
|
|
325
|
+
}
|
|
326
|
+
const keysThatTriggerDefault = ['ArrowDown', 'ArrowUp'];
|
|
327
|
+
if (keysThatTriggerDefault.includes(event.key)) {
|
|
328
|
+
event.preventDefault();
|
|
329
|
+
this.setDefaultActiveElement();
|
|
330
|
+
}
|
|
331
|
+
else {
|
|
332
|
+
this.keydownHandler(event, true);
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
/// DOM ///
|
|
336
|
+
render() {
|
|
337
|
+
return (h(Host, null,
|
|
338
|
+
h("div", { class: "content", ref: el => (this.contentElement = el), onFocusout: this.focusoutHandler },
|
|
339
|
+
h("div", { class: "options", role: this.type || 'listbox', onKeyDown: this.keydownHandler, onClick: this.clickHandler },
|
|
340
|
+
h("slot", null)))));
|
|
341
|
+
}
|
|
342
|
+
static get is() { return "q2-option-list"; }
|
|
343
|
+
static get encapsulation() { return "shadow"; }
|
|
344
|
+
static get originalStyleUrls() { return {
|
|
345
|
+
"$": ["styles.scss"]
|
|
346
|
+
}; }
|
|
347
|
+
static get styleUrls() { return {
|
|
348
|
+
"$": ["styles.css"]
|
|
349
|
+
}; }
|
|
350
|
+
static get properties() { return {
|
|
351
|
+
"role": {
|
|
352
|
+
"type": "string",
|
|
353
|
+
"mutable": false,
|
|
354
|
+
"complexType": {
|
|
355
|
+
"original": "'listbox' | 'menu'",
|
|
356
|
+
"resolved": "\"listbox\" | \"menu\"",
|
|
357
|
+
"references": {}
|
|
358
|
+
},
|
|
359
|
+
"required": false,
|
|
360
|
+
"optional": false,
|
|
361
|
+
"docs": {
|
|
362
|
+
"tags": [],
|
|
363
|
+
"text": ""
|
|
364
|
+
},
|
|
365
|
+
"attribute": "role",
|
|
366
|
+
"reflect": true,
|
|
367
|
+
"defaultValue": "'listbox'"
|
|
368
|
+
},
|
|
369
|
+
"direction": {
|
|
370
|
+
"type": "string",
|
|
371
|
+
"mutable": false,
|
|
372
|
+
"complexType": {
|
|
373
|
+
"original": "'up' | 'down'",
|
|
374
|
+
"resolved": "\"down\" | \"up\"",
|
|
375
|
+
"references": {}
|
|
376
|
+
},
|
|
377
|
+
"required": false,
|
|
378
|
+
"optional": false,
|
|
379
|
+
"docs": {
|
|
380
|
+
"tags": [],
|
|
381
|
+
"text": ""
|
|
382
|
+
},
|
|
383
|
+
"attribute": "direction",
|
|
384
|
+
"reflect": true,
|
|
385
|
+
"defaultValue": "'down'"
|
|
386
|
+
},
|
|
387
|
+
"open": {
|
|
388
|
+
"type": "boolean",
|
|
389
|
+
"mutable": true,
|
|
390
|
+
"complexType": {
|
|
391
|
+
"original": "boolean",
|
|
392
|
+
"resolved": "boolean",
|
|
393
|
+
"references": {}
|
|
394
|
+
},
|
|
395
|
+
"required": false,
|
|
396
|
+
"optional": false,
|
|
397
|
+
"docs": {
|
|
398
|
+
"tags": [],
|
|
399
|
+
"text": ""
|
|
400
|
+
},
|
|
401
|
+
"attribute": "open",
|
|
402
|
+
"reflect": true
|
|
403
|
+
},
|
|
404
|
+
"customSearch": {
|
|
405
|
+
"type": "boolean",
|
|
406
|
+
"mutable": false,
|
|
407
|
+
"complexType": {
|
|
408
|
+
"original": "boolean",
|
|
409
|
+
"resolved": "boolean",
|
|
410
|
+
"references": {}
|
|
411
|
+
},
|
|
412
|
+
"required": false,
|
|
413
|
+
"optional": false,
|
|
414
|
+
"docs": {
|
|
415
|
+
"tags": [],
|
|
416
|
+
"text": ""
|
|
417
|
+
},
|
|
418
|
+
"attribute": "custom-search",
|
|
419
|
+
"reflect": true
|
|
420
|
+
},
|
|
421
|
+
"noSelect": {
|
|
422
|
+
"type": "boolean",
|
|
423
|
+
"mutable": false,
|
|
424
|
+
"complexType": {
|
|
425
|
+
"original": "boolean",
|
|
426
|
+
"resolved": "boolean",
|
|
427
|
+
"references": {}
|
|
428
|
+
},
|
|
429
|
+
"required": false,
|
|
430
|
+
"optional": false,
|
|
431
|
+
"docs": {
|
|
432
|
+
"tags": [],
|
|
433
|
+
"text": ""
|
|
434
|
+
},
|
|
435
|
+
"attribute": "no-select",
|
|
436
|
+
"reflect": true
|
|
437
|
+
},
|
|
438
|
+
"align": {
|
|
439
|
+
"type": "string",
|
|
440
|
+
"mutable": false,
|
|
441
|
+
"complexType": {
|
|
442
|
+
"original": "'left' | 'right'",
|
|
443
|
+
"resolved": "\"left\" | \"right\"",
|
|
444
|
+
"references": {}
|
|
445
|
+
},
|
|
446
|
+
"required": false,
|
|
447
|
+
"optional": false,
|
|
448
|
+
"docs": {
|
|
449
|
+
"tags": [],
|
|
450
|
+
"text": ""
|
|
451
|
+
},
|
|
452
|
+
"attribute": "align",
|
|
453
|
+
"reflect": true
|
|
454
|
+
},
|
|
455
|
+
"selectedOptions": {
|
|
456
|
+
"type": "unknown",
|
|
457
|
+
"mutable": true,
|
|
458
|
+
"complexType": {
|
|
459
|
+
"original": "IOptionValue[]",
|
|
460
|
+
"resolved": "IOptionValue[]",
|
|
461
|
+
"references": {
|
|
462
|
+
"IOptionValue": {
|
|
463
|
+
"location": "local"
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
},
|
|
467
|
+
"required": false,
|
|
468
|
+
"optional": false,
|
|
469
|
+
"docs": {
|
|
470
|
+
"tags": [],
|
|
471
|
+
"text": ""
|
|
472
|
+
},
|
|
473
|
+
"defaultValue": "[]"
|
|
474
|
+
},
|
|
475
|
+
"multiple": {
|
|
476
|
+
"type": "boolean",
|
|
477
|
+
"mutable": false,
|
|
478
|
+
"complexType": {
|
|
479
|
+
"original": "boolean",
|
|
480
|
+
"resolved": "boolean",
|
|
481
|
+
"references": {}
|
|
482
|
+
},
|
|
483
|
+
"required": false,
|
|
484
|
+
"optional": false,
|
|
485
|
+
"docs": {
|
|
486
|
+
"tags": [],
|
|
487
|
+
"text": ""
|
|
488
|
+
},
|
|
489
|
+
"attribute": "multiple",
|
|
490
|
+
"reflect": true
|
|
491
|
+
},
|
|
492
|
+
"disabled": {
|
|
493
|
+
"type": "boolean",
|
|
494
|
+
"mutable": false,
|
|
495
|
+
"complexType": {
|
|
496
|
+
"original": "boolean",
|
|
497
|
+
"resolved": "boolean",
|
|
498
|
+
"references": {}
|
|
499
|
+
},
|
|
500
|
+
"required": false,
|
|
501
|
+
"optional": false,
|
|
502
|
+
"docs": {
|
|
503
|
+
"tags": [],
|
|
504
|
+
"text": ""
|
|
505
|
+
},
|
|
506
|
+
"attribute": "disabled",
|
|
507
|
+
"reflect": true
|
|
508
|
+
},
|
|
509
|
+
"type": {
|
|
510
|
+
"type": "string",
|
|
511
|
+
"mutable": false,
|
|
512
|
+
"complexType": {
|
|
513
|
+
"original": "'menu' | 'listbox'",
|
|
514
|
+
"resolved": "\"listbox\" | \"menu\"",
|
|
515
|
+
"references": {}
|
|
516
|
+
},
|
|
517
|
+
"required": false,
|
|
518
|
+
"optional": false,
|
|
519
|
+
"docs": {
|
|
520
|
+
"tags": [],
|
|
521
|
+
"text": ""
|
|
522
|
+
},
|
|
523
|
+
"attribute": "type",
|
|
524
|
+
"reflect": false
|
|
525
|
+
}
|
|
526
|
+
}; }
|
|
527
|
+
static get states() { return {
|
|
528
|
+
"hasOptions": {}
|
|
529
|
+
}; }
|
|
530
|
+
static get events() { return [{
|
|
531
|
+
"method": "change",
|
|
532
|
+
"name": "change",
|
|
533
|
+
"bubbles": true,
|
|
534
|
+
"cancelable": true,
|
|
535
|
+
"composed": true,
|
|
536
|
+
"docs": {
|
|
537
|
+
"tags": [],
|
|
538
|
+
"text": ""
|
|
539
|
+
},
|
|
540
|
+
"complexType": {
|
|
541
|
+
"original": "{ value: string; values: IOptionValue[] }",
|
|
542
|
+
"resolved": "{ value: string; values: IOptionValue[]; }",
|
|
543
|
+
"references": {
|
|
544
|
+
"IOptionValue": {
|
|
545
|
+
"location": "local"
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
}, {
|
|
550
|
+
"method": "optionListState",
|
|
551
|
+
"name": "optionListState",
|
|
552
|
+
"bubbles": true,
|
|
553
|
+
"cancelable": true,
|
|
554
|
+
"composed": true,
|
|
555
|
+
"docs": {
|
|
556
|
+
"tags": [],
|
|
557
|
+
"text": ""
|
|
558
|
+
},
|
|
559
|
+
"complexType": {
|
|
560
|
+
"original": "{ open: boolean }",
|
|
561
|
+
"resolved": "{ open: boolean; }",
|
|
562
|
+
"references": {}
|
|
563
|
+
}
|
|
564
|
+
}]; }
|
|
565
|
+
static get methods() { return {
|
|
566
|
+
"toggle": {
|
|
567
|
+
"complexType": {
|
|
568
|
+
"signature": "() => Promise<void>",
|
|
569
|
+
"parameters": [],
|
|
570
|
+
"references": {},
|
|
571
|
+
"return": "Promise<void>"
|
|
572
|
+
},
|
|
573
|
+
"docs": {
|
|
574
|
+
"text": "",
|
|
575
|
+
"tags": []
|
|
576
|
+
}
|
|
577
|
+
},
|
|
578
|
+
"setDefaultActiveElement": {
|
|
579
|
+
"complexType": {
|
|
580
|
+
"signature": "() => Promise<void>",
|
|
581
|
+
"parameters": [],
|
|
582
|
+
"references": {},
|
|
583
|
+
"return": "Promise<void>"
|
|
584
|
+
},
|
|
585
|
+
"docs": {
|
|
586
|
+
"text": "",
|
|
587
|
+
"tags": []
|
|
588
|
+
}
|
|
589
|
+
},
|
|
590
|
+
"setActiveElement": {
|
|
591
|
+
"complexType": {
|
|
592
|
+
"signature": "(index: number) => Promise<void>",
|
|
593
|
+
"parameters": [{
|
|
594
|
+
"tags": [],
|
|
595
|
+
"text": ""
|
|
596
|
+
}],
|
|
597
|
+
"references": {},
|
|
598
|
+
"return": "Promise<void>"
|
|
599
|
+
},
|
|
600
|
+
"docs": {
|
|
601
|
+
"text": "",
|
|
602
|
+
"tags": []
|
|
603
|
+
}
|
|
604
|
+
},
|
|
605
|
+
"handleExternalKeydown": {
|
|
606
|
+
"complexType": {
|
|
607
|
+
"signature": "(event: KeyboardEvent) => Promise<void>",
|
|
608
|
+
"parameters": [{
|
|
609
|
+
"tags": [],
|
|
610
|
+
"text": ""
|
|
611
|
+
}],
|
|
612
|
+
"references": {
|
|
613
|
+
"KeyboardEvent": {
|
|
614
|
+
"location": "global"
|
|
615
|
+
}
|
|
616
|
+
},
|
|
617
|
+
"return": "Promise<void>"
|
|
618
|
+
},
|
|
619
|
+
"docs": {
|
|
620
|
+
"text": "",
|
|
621
|
+
"tags": []
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
}; }
|
|
625
|
+
static get elementRef() { return "hostElement"; }
|
|
626
|
+
static get watchers() { return [{
|
|
627
|
+
"propName": "selectedOptions",
|
|
628
|
+
"methodName": "selectedOptionsUpdated"
|
|
629
|
+
}, {
|
|
630
|
+
"propName": "open",
|
|
631
|
+
"methodName": "openChanged"
|
|
632
|
+
}]; }
|
|
633
|
+
static get listeners() { return [{
|
|
634
|
+
"name": "focus",
|
|
635
|
+
"method": "delegateFocus",
|
|
636
|
+
"target": undefined,
|
|
637
|
+
"capture": false,
|
|
638
|
+
"passive": false
|
|
639
|
+
}, {
|
|
640
|
+
"name": "click",
|
|
641
|
+
"method": "handleClick",
|
|
642
|
+
"target": undefined,
|
|
643
|
+
"capture": false,
|
|
644
|
+
"passive": false
|
|
645
|
+
}]; }
|
|
646
|
+
}
|