@triptease/tt-combobox 5.7.0 → 5.7.2
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/src/TtCombobox.js +507 -0
- package/dist/cjs/src/TtCombobox.js.map +1 -0
- package/dist/cjs/src/index.js +21 -0
- package/dist/cjs/src/index.js.map +1 -0
- package/dist/cjs/src/styles.js +225 -0
- package/dist/cjs/src/styles.js.map +1 -0
- package/dist/cjs/src/tt-combobox.js +12 -0
- package/dist/cjs/src/tt-combobox.js.map +1 -0
- package/dist/cjs/src/tt-option/TtOption.js +81 -0
- package/dist/cjs/src/tt-option/TtOption.js.map +1 -0
- package/dist/cjs/src/tt-option/styles.js +75 -0
- package/dist/cjs/src/tt-option/styles.js.map +1 -0
- package/dist/cjs/src/tt-option/tt-option.js +11 -0
- package/dist/cjs/src/tt-option/tt-option.js.map +1 -0
- package/dist/cjs/src/types.js +3 -0
- package/dist/cjs/src/types.js.map +1 -0
- package/package.json +7 -3
- package/CHANGELOG.md +0 -174
- package/custom-elements.json +0 -847
- package/test/tt-combobox.test.ts +0 -664
- package/tsconfig.cjs.json +0 -9
- package/tsconfig.json +0 -9
|
@@ -0,0 +1,507 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.TtCombobox = void 0;
|
|
10
|
+
const lit_1 = require("lit");
|
|
11
|
+
const decorators_js_1 = require("lit/decorators.js");
|
|
12
|
+
const if_defined_js_1 = require("lit/directives/if-defined.js");
|
|
13
|
+
const repeat_js_1 = require("lit/directives/repeat.js");
|
|
14
|
+
const unsafe_html_js_1 = require("lit/directives/unsafe-html.js");
|
|
15
|
+
const unsafe_svg_js_1 = require("lit/directives/unsafe-svg.js");
|
|
16
|
+
const guard_js_1 = require("lit/directives/guard.js");
|
|
17
|
+
const icons_1 = require("@triptease/icons");
|
|
18
|
+
const styles_js_1 = require("./styles.js");
|
|
19
|
+
class TtCombobox extends lit_1.LitElement {
|
|
20
|
+
get form() {
|
|
21
|
+
return this.internals.form;
|
|
22
|
+
}
|
|
23
|
+
get _isAllSelected() {
|
|
24
|
+
return (Boolean(this._visibleOptionsNotSelectAll.length) &&
|
|
25
|
+
Array.from(this._visibleOptionsNotSelectAll).every((option) => this.value.includes(option.value)));
|
|
26
|
+
}
|
|
27
|
+
get _selectedVisibleOptions() {
|
|
28
|
+
return Array.from(this._visibleOptions).filter((option) => this.value.includes(option.value));
|
|
29
|
+
}
|
|
30
|
+
get _selectedOptions() {
|
|
31
|
+
return Array.from(this._visibleOptionsNotSelectAll).filter((option) => this.value.includes(option.value));
|
|
32
|
+
}
|
|
33
|
+
constructor() {
|
|
34
|
+
super();
|
|
35
|
+
this.multiselect = false;
|
|
36
|
+
this.disabled = false;
|
|
37
|
+
this.invalid = false;
|
|
38
|
+
this.displaySelectAll = false;
|
|
39
|
+
this.required = false;
|
|
40
|
+
this.name = '';
|
|
41
|
+
this.ariaLabelledby = lit_1.nothing;
|
|
42
|
+
this.hideCaret = false;
|
|
43
|
+
this.openUpward = false;
|
|
44
|
+
this._activeOption = -1;
|
|
45
|
+
this._expanded = false;
|
|
46
|
+
this._filter = '';
|
|
47
|
+
this.value = [];
|
|
48
|
+
this._slotObserver = new MutationObserver((mutations) => {
|
|
49
|
+
mutations.forEach((mutation) => {
|
|
50
|
+
if (mutation.type === 'attributes') {
|
|
51
|
+
this.requestUpdate('options');
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
this._valueChanged = () => {
|
|
56
|
+
this._selectableOptions.forEach((option) => {
|
|
57
|
+
if (this.value.includes(option.value)) {
|
|
58
|
+
this._checkOption(option);
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
this._uncheckOption(option);
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
this.internals.setFormValue(JSON.stringify(this.value));
|
|
65
|
+
};
|
|
66
|
+
this._listenForOptionChange = () => {
|
|
67
|
+
this.options.forEach((option) => {
|
|
68
|
+
this._slotObserver.observe(option, { attributes: true, attributeFilter: ['selected', 'disabled', 'hidden'] });
|
|
69
|
+
});
|
|
70
|
+
};
|
|
71
|
+
this._selectAll = (event) => {
|
|
72
|
+
event.preventDefault();
|
|
73
|
+
event.stopPropagation();
|
|
74
|
+
// If filtering, and all visible options are selected, deselect only visible options
|
|
75
|
+
// Else if filtering, select all visible options
|
|
76
|
+
if (this._filter !== '' && this._isAllSelected) {
|
|
77
|
+
const selectedVisibleValues = this._selectedVisibleOptions.map((option) => option.value);
|
|
78
|
+
this.value = this.value.filter((value) => !selectedVisibleValues.includes(value));
|
|
79
|
+
}
|
|
80
|
+
else if (this._filter !== '') {
|
|
81
|
+
this.value = Array.from(new Set([...this.value, ...Array.from(this._selectableVisibleOptions).map((option) => option.value)]));
|
|
82
|
+
}
|
|
83
|
+
else if (this.value.length === this._selectableOptions.length) {
|
|
84
|
+
this.value = [];
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
this.value = Array.from(this._selectableOptions).map((option) => option.value);
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
this._renderSelectAll = () => {
|
|
91
|
+
if (!this.multiselect || !this.displaySelectAll) {
|
|
92
|
+
return lit_1.nothing;
|
|
93
|
+
}
|
|
94
|
+
const id = `${this.id}-option-select-all`;
|
|
95
|
+
const active = this._getActiveOptionId() === id;
|
|
96
|
+
const selected = this._isAllSelected;
|
|
97
|
+
return (0, lit_1.html) `
|
|
98
|
+
<tt-option
|
|
99
|
+
id="${id}"
|
|
100
|
+
class="select-all"
|
|
101
|
+
?selected=${selected}
|
|
102
|
+
?active=${active}
|
|
103
|
+
include-checkbox
|
|
104
|
+
@click="${this._selectAll}"
|
|
105
|
+
exportparts="option, checkbox"
|
|
106
|
+
part="option"
|
|
107
|
+
value="select-all"
|
|
108
|
+
>Select all</tt-option
|
|
109
|
+
>
|
|
110
|
+
`;
|
|
111
|
+
};
|
|
112
|
+
this._renderChevron = () => (0, lit_1.html) `
|
|
113
|
+
<button
|
|
114
|
+
type="button"
|
|
115
|
+
aria-label="Expand"
|
|
116
|
+
@click="${this._onChevronClick}"
|
|
117
|
+
aria-expanded="${this._expanded}"
|
|
118
|
+
aria-controls="${this.id}-list"
|
|
119
|
+
tabindex="-1"
|
|
120
|
+
?disabled=${this.disabled}
|
|
121
|
+
part="arrow"
|
|
122
|
+
>
|
|
123
|
+
${(0, unsafe_svg_js_1.unsafeSVG)(icons_1.chevronDown)}
|
|
124
|
+
</button>
|
|
125
|
+
`;
|
|
126
|
+
this.internals = this.attachInternals();
|
|
127
|
+
}
|
|
128
|
+
_handleFocusOut(e) {
|
|
129
|
+
if (!this.shadowRoot.contains(e.relatedTarget)) {
|
|
130
|
+
this._expanded = false;
|
|
131
|
+
}
|
|
132
|
+
this._filter = '';
|
|
133
|
+
}
|
|
134
|
+
_onFocus() {
|
|
135
|
+
this._comboboxInput.focus();
|
|
136
|
+
}
|
|
137
|
+
connectedCallback() {
|
|
138
|
+
super.connectedCallback();
|
|
139
|
+
this.addEventListener('focus', this._onFocus);
|
|
140
|
+
}
|
|
141
|
+
disconnectedCallback() {
|
|
142
|
+
super.disconnectedCallback();
|
|
143
|
+
this.removeEventListener('focus', this._onFocus);
|
|
144
|
+
}
|
|
145
|
+
firstUpdated(changedProperties) {
|
|
146
|
+
this.internals.setFormValue(JSON.stringify(this.value));
|
|
147
|
+
this._reportValidity();
|
|
148
|
+
this._listenForOptionChange();
|
|
149
|
+
super.firstUpdated(changedProperties);
|
|
150
|
+
}
|
|
151
|
+
update(changedProperties) {
|
|
152
|
+
if (changedProperties.has('value')) {
|
|
153
|
+
this._valueChanged();
|
|
154
|
+
if (changedProperties.get('value') !== undefined &&
|
|
155
|
+
JSON.stringify(changedProperties.get('value')) !== JSON.stringify(this.value)) {
|
|
156
|
+
this._dispatchSelectedOptions();
|
|
157
|
+
this._reportValidity();
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
if (changedProperties.has('_expanded') && changedProperties.get('_expanded') && !this._expanded) {
|
|
161
|
+
this.internals.states.add('interacted');
|
|
162
|
+
}
|
|
163
|
+
if (changedProperties.has('options')) {
|
|
164
|
+
this.updateComplete.then(() => {
|
|
165
|
+
const selectedAssignedOptions = Array.from(this.options).filter((option) => option.selected);
|
|
166
|
+
this.value = Array.from(new Set([...this.value, ...selectedAssignedOptions.map((option) => option.value)]));
|
|
167
|
+
this._listenForOptionChange();
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
super.update(changedProperties);
|
|
171
|
+
}
|
|
172
|
+
_reportValidity() {
|
|
173
|
+
if (this.required && !this.value.length) {
|
|
174
|
+
const errorMessage = this.multiselect ? 'Please select at least one option' : 'Please select an option';
|
|
175
|
+
this.internals.setValidity({
|
|
176
|
+
valueMissing: true,
|
|
177
|
+
}, errorMessage, this._comboboxInput);
|
|
178
|
+
this.internals.states.add('--invalid');
|
|
179
|
+
}
|
|
180
|
+
else if (!this.internals.validity.valid) {
|
|
181
|
+
this.internals.setValidity({});
|
|
182
|
+
if (this.internals.states.has('--invalid')) {
|
|
183
|
+
this.internals.states.delete('--invalid');
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
get labels() {
|
|
188
|
+
return [...this.internals.labels];
|
|
189
|
+
}
|
|
190
|
+
get labelContent() {
|
|
191
|
+
if (this.ariaLabel !== null) {
|
|
192
|
+
return this.ariaLabel;
|
|
193
|
+
}
|
|
194
|
+
return this.labels.map((label) => label.innerText).join(', ');
|
|
195
|
+
}
|
|
196
|
+
_onKeyUp(event) {
|
|
197
|
+
switch (event.key) {
|
|
198
|
+
case 'ArrowDown':
|
|
199
|
+
event.preventDefault();
|
|
200
|
+
if (!this._expanded) {
|
|
201
|
+
this._expanded = true;
|
|
202
|
+
this._activeOption = -1;
|
|
203
|
+
}
|
|
204
|
+
else {
|
|
205
|
+
this._activeOption = Math.min(this._visibleOptions.length - 1, this._activeOption + 1);
|
|
206
|
+
}
|
|
207
|
+
break;
|
|
208
|
+
case 'ArrowUp':
|
|
209
|
+
event.preventDefault();
|
|
210
|
+
if (this._expanded) {
|
|
211
|
+
this._activeOption = Math.max(0, this._activeOption - 1);
|
|
212
|
+
}
|
|
213
|
+
break;
|
|
214
|
+
case 'Escape':
|
|
215
|
+
event.preventDefault();
|
|
216
|
+
if (this._expanded) {
|
|
217
|
+
this._expanded = false;
|
|
218
|
+
}
|
|
219
|
+
else if (this._filter !== '') {
|
|
220
|
+
this._filter = '';
|
|
221
|
+
}
|
|
222
|
+
break;
|
|
223
|
+
case 'Enter':
|
|
224
|
+
event.preventDefault();
|
|
225
|
+
if (this._expanded) {
|
|
226
|
+
this._visibleOptions[this._activeOption].click();
|
|
227
|
+
}
|
|
228
|
+
break;
|
|
229
|
+
default:
|
|
230
|
+
break;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
_uncheckOption(option) {
|
|
234
|
+
if (option.dataset.deselectable !== 'true')
|
|
235
|
+
return;
|
|
236
|
+
option.setAttribute('aria-selected', 'false');
|
|
237
|
+
const checkbox = option.querySelector('input[type="checkbox"]');
|
|
238
|
+
if (checkbox) {
|
|
239
|
+
checkbox.checked = false;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
_checkOption(option) {
|
|
243
|
+
if (!this.multiselect) {
|
|
244
|
+
this._selectableOptions.forEach((opt) => {
|
|
245
|
+
this._uncheckOption(opt);
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
option.setAttribute('aria-selected', 'true');
|
|
249
|
+
const checkbox = option.querySelector('input[type="checkbox"]');
|
|
250
|
+
if (checkbox) {
|
|
251
|
+
checkbox.checked = true;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
_getActiveOptionId() {
|
|
255
|
+
if (this._activeOption === -1 || this._visibleOptions.length === 0) {
|
|
256
|
+
return undefined;
|
|
257
|
+
}
|
|
258
|
+
const option = this._visibleOptions[this._activeOption];
|
|
259
|
+
return option.id;
|
|
260
|
+
}
|
|
261
|
+
_onClick() {
|
|
262
|
+
this._expanded = !this._expanded;
|
|
263
|
+
if (this._expanded) {
|
|
264
|
+
this.shadowRoot?.querySelector('input[role="combobox"]')?.focus();
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
_onChevronClick() {
|
|
268
|
+
this.shadowRoot?.querySelector('input[role="combobox"]')?.focus();
|
|
269
|
+
}
|
|
270
|
+
_onClickOption(event) {
|
|
271
|
+
event.preventDefault();
|
|
272
|
+
event.stopPropagation();
|
|
273
|
+
const option = event.currentTarget;
|
|
274
|
+
if (option.disabled)
|
|
275
|
+
return;
|
|
276
|
+
const selectedValue = option.value;
|
|
277
|
+
if (this.multiselect) {
|
|
278
|
+
if (this.value.includes(selectedValue)) {
|
|
279
|
+
this.value = this.value.filter((value) => value !== selectedValue);
|
|
280
|
+
}
|
|
281
|
+
else {
|
|
282
|
+
this.value = [...this.value, selectedValue];
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
else {
|
|
286
|
+
this.value = [selectedValue];
|
|
287
|
+
this._expanded = false;
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
_onInput(event) {
|
|
291
|
+
const input = event.target;
|
|
292
|
+
const filter = input.value;
|
|
293
|
+
if (filter !== '' && !this._expanded) {
|
|
294
|
+
this._expanded = true;
|
|
295
|
+
}
|
|
296
|
+
this._activeOption = -1;
|
|
297
|
+
this._filter = filter;
|
|
298
|
+
}
|
|
299
|
+
_dispatchSelectedOptions() {
|
|
300
|
+
this.dispatchEvent(new Event('change', {
|
|
301
|
+
bubbles: true,
|
|
302
|
+
composed: true,
|
|
303
|
+
}));
|
|
304
|
+
}
|
|
305
|
+
get _isValid() {
|
|
306
|
+
return this.internals.validity.valid && !this.invalid;
|
|
307
|
+
}
|
|
308
|
+
_renderCombobox() {
|
|
309
|
+
const placeHolderValue = (0, guard_js_1.guard)([this.placeholder, this.disabled, this.value, this.activeOptions.length, this.selectAllPlaceholder, this._filter], () => {
|
|
310
|
+
if (this.placeholder) {
|
|
311
|
+
return this.placeholder;
|
|
312
|
+
}
|
|
313
|
+
if (this.disabled) {
|
|
314
|
+
return 'Disabled';
|
|
315
|
+
}
|
|
316
|
+
if (!this.value.length) {
|
|
317
|
+
return 'No options selected';
|
|
318
|
+
}
|
|
319
|
+
if (this.value.length === 1) {
|
|
320
|
+
return Array.from(this._selectableVisibleOptions)
|
|
321
|
+
.find((option) => option.value === this.value[0])
|
|
322
|
+
?.textContent?.trim();
|
|
323
|
+
}
|
|
324
|
+
// Count all selected values, excluding only those that correspond to permanently hidden options
|
|
325
|
+
const permanentlyHiddenValues = Array.from(this.options)
|
|
326
|
+
.filter((option) => option.hidden)
|
|
327
|
+
.map((option) => option.value);
|
|
328
|
+
const selectedCount = this.value.filter((val) => !permanentlyHiddenValues.includes(val)).length;
|
|
329
|
+
// Only show "All options selected" when truly all non-hidden options are selected
|
|
330
|
+
const totalSelectableCount = this.options.length - permanentlyHiddenValues.length;
|
|
331
|
+
if (this._filter === '' && selectedCount === totalSelectableCount && totalSelectableCount > 0) {
|
|
332
|
+
return this.selectAllPlaceholder || 'All options selected';
|
|
333
|
+
}
|
|
334
|
+
return `${selectedCount} options selected`;
|
|
335
|
+
});
|
|
336
|
+
return (0, lit_1.html) ` <input
|
|
337
|
+
type="text"
|
|
338
|
+
id="${this.id}"
|
|
339
|
+
name="${this.name}"
|
|
340
|
+
autocomplete="off"
|
|
341
|
+
aria-label="${this.labelContent}"
|
|
342
|
+
aria-labelledby="${this.ariaLabelledby}"
|
|
343
|
+
role="combobox"
|
|
344
|
+
aria-controls="${this.id}-list"
|
|
345
|
+
aria-expanded="${this._expanded}"
|
|
346
|
+
aria-autocomplete="list"
|
|
347
|
+
aria-haspopup="listbox"
|
|
348
|
+
aria-disabled="${this.disabled}"
|
|
349
|
+
aria-invalid="${!this._isValid}"
|
|
350
|
+
aria-errormessage="${!this._isValid ? `error-msg-${this.id}` : lit_1.nothing}"
|
|
351
|
+
aria-required="${this.required}"
|
|
352
|
+
?disabled=${this.disabled}
|
|
353
|
+
aria-activedescendant="${(0, if_defined_js_1.ifDefined)(this._getActiveOptionId())}"
|
|
354
|
+
@input="${this._onInput}"
|
|
355
|
+
.value="${this._filter}"
|
|
356
|
+
.placeholder="${placeHolderValue}"
|
|
357
|
+
@focusout="${this._handleFocusOut}"
|
|
358
|
+
part="input"
|
|
359
|
+
class=${this.hideCaret ? 'hide-caret' : ''}
|
|
360
|
+
/>`;
|
|
361
|
+
}
|
|
362
|
+
_renderOption(option) {
|
|
363
|
+
const hidden = Boolean((this._filter !== '' &&
|
|
364
|
+
!option.value.toLowerCase().includes(this._filter.toLowerCase()) &&
|
|
365
|
+
!option.innerText.toLowerCase().includes(this._filter.toLowerCase())) ||
|
|
366
|
+
option.hidden);
|
|
367
|
+
const id = `${this.id}-option-${option.value}`;
|
|
368
|
+
const active = this._getActiveOptionId() === id;
|
|
369
|
+
const selected = this.value.includes(option.value);
|
|
370
|
+
return (0, lit_1.html) `
|
|
371
|
+
<tt-option
|
|
372
|
+
id="${id}"
|
|
373
|
+
value="${option.value}"
|
|
374
|
+
?selected=${selected}
|
|
375
|
+
?disabled=${option.disabled}
|
|
376
|
+
?active=${active}
|
|
377
|
+
?include-checkbox=${this.multiselect}
|
|
378
|
+
?hidden=${hidden}
|
|
379
|
+
@click="${this._onClickOption}"
|
|
380
|
+
>
|
|
381
|
+
${(0, unsafe_html_js_1.unsafeHTML)(option.innerHTML)}
|
|
382
|
+
</tt-option>
|
|
383
|
+
`;
|
|
384
|
+
}
|
|
385
|
+
_hasErrorContent() {
|
|
386
|
+
return this.errorElements?.length > 0;
|
|
387
|
+
}
|
|
388
|
+
render() {
|
|
389
|
+
return (0, lit_1.html) `
|
|
390
|
+
<div
|
|
391
|
+
class="tt-combobox-container"
|
|
392
|
+
@focus="${this._onFocus}"
|
|
393
|
+
@keydown="${this._onKeyUp}"
|
|
394
|
+
@click="${this._onClick}"
|
|
395
|
+
aria-disabled="${this.disabled}"
|
|
396
|
+
part="container"
|
|
397
|
+
>
|
|
398
|
+
<slot name="icon" part="icon"></slot>
|
|
399
|
+
${this._renderCombobox()} ${this._renderChevron()}
|
|
400
|
+
<ul
|
|
401
|
+
id="${this.id}-list"
|
|
402
|
+
role="listbox"
|
|
403
|
+
aria-multiselectable="${this.multiselect}"
|
|
404
|
+
aria-label="${this.labelContent}"
|
|
405
|
+
part="listbox"
|
|
406
|
+
?data-open-upward="${this.openUpward}"
|
|
407
|
+
>
|
|
408
|
+
${this._renderSelectAll()} ${(0, repeat_js_1.repeat)(this.options, (opt) => opt.value, this._renderOption.bind(this))}
|
|
409
|
+
|
|
410
|
+
<li part="no-results" class="no-results">No results</li>
|
|
411
|
+
</ul>
|
|
412
|
+
</div>
|
|
413
|
+
<slot name="option" @slotchange=${() => this.requestUpdate('options')}></slot>
|
|
414
|
+
<div
|
|
415
|
+
class="errormessage"
|
|
416
|
+
id="error-msg-${this.id}"
|
|
417
|
+
role="alert"
|
|
418
|
+
aria-atomic="true"
|
|
419
|
+
?data-hidden="${!this._hasErrorContent()}"
|
|
420
|
+
part="error"
|
|
421
|
+
>
|
|
422
|
+
${(0, unsafe_svg_js_1.unsafeSVG)(icons_1.alert)}
|
|
423
|
+
<slot name="error"></slot>
|
|
424
|
+
</div>
|
|
425
|
+
`;
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
exports.TtCombobox = TtCombobox;
|
|
429
|
+
TtCombobox.styles = styles_js_1.styles;
|
|
430
|
+
TtCombobox.formAssociated = true;
|
|
431
|
+
TtCombobox.shadowRootOptions = {
|
|
432
|
+
...lit_1.LitElement.shadowRootOptions,
|
|
433
|
+
delegatesFocus: true,
|
|
434
|
+
};
|
|
435
|
+
__decorate([
|
|
436
|
+
(0, decorators_js_1.property)({ type: Boolean })
|
|
437
|
+
], TtCombobox.prototype, "multiselect", void 0);
|
|
438
|
+
__decorate([
|
|
439
|
+
(0, decorators_js_1.property)({ type: Boolean })
|
|
440
|
+
], TtCombobox.prototype, "disabled", void 0);
|
|
441
|
+
__decorate([
|
|
442
|
+
(0, decorators_js_1.property)({ type: Boolean })
|
|
443
|
+
], TtCombobox.prototype, "invalid", void 0);
|
|
444
|
+
__decorate([
|
|
445
|
+
(0, decorators_js_1.property)({ type: Boolean, attribute: 'display-select-all' })
|
|
446
|
+
], TtCombobox.prototype, "displaySelectAll", void 0);
|
|
447
|
+
__decorate([
|
|
448
|
+
(0, decorators_js_1.property)({ type: Boolean })
|
|
449
|
+
], TtCombobox.prototype, "required", void 0);
|
|
450
|
+
__decorate([
|
|
451
|
+
(0, decorators_js_1.property)({ type: String })
|
|
452
|
+
], TtCombobox.prototype, "name", void 0);
|
|
453
|
+
__decorate([
|
|
454
|
+
(0, decorators_js_1.property)({ type: String, attribute: 'aria-labelledby' })
|
|
455
|
+
], TtCombobox.prototype, "ariaLabelledby", void 0);
|
|
456
|
+
__decorate([
|
|
457
|
+
(0, decorators_js_1.property)({ type: Boolean, attribute: 'hide-caret' })
|
|
458
|
+
], TtCombobox.prototype, "hideCaret", void 0);
|
|
459
|
+
__decorate([
|
|
460
|
+
(0, decorators_js_1.property)({ type: String })
|
|
461
|
+
], TtCombobox.prototype, "placeholder", void 0);
|
|
462
|
+
__decorate([
|
|
463
|
+
(0, decorators_js_1.property)({ type: String, attribute: 'select-all-placeholder' })
|
|
464
|
+
], TtCombobox.prototype, "selectAllPlaceholder", void 0);
|
|
465
|
+
__decorate([
|
|
466
|
+
(0, decorators_js_1.property)({ type: Boolean, attribute: 'open-upward' })
|
|
467
|
+
], TtCombobox.prototype, "openUpward", void 0);
|
|
468
|
+
__decorate([
|
|
469
|
+
(0, decorators_js_1.state)()
|
|
470
|
+
], TtCombobox.prototype, "_activeOption", void 0);
|
|
471
|
+
__decorate([
|
|
472
|
+
(0, decorators_js_1.state)()
|
|
473
|
+
], TtCombobox.prototype, "_expanded", void 0);
|
|
474
|
+
__decorate([
|
|
475
|
+
(0, decorators_js_1.state)()
|
|
476
|
+
], TtCombobox.prototype, "_filter", void 0);
|
|
477
|
+
__decorate([
|
|
478
|
+
(0, decorators_js_1.queryAssignedElements)({ slot: 'option', selector: 'option' })
|
|
479
|
+
], TtCombobox.prototype, "options", void 0);
|
|
480
|
+
__decorate([
|
|
481
|
+
(0, decorators_js_1.queryAssignedElements)({ slot: 'option', selector: 'tt-option:not([disabled])' })
|
|
482
|
+
], TtCombobox.prototype, "activeOptions", void 0);
|
|
483
|
+
__decorate([
|
|
484
|
+
(0, decorators_js_1.queryAssignedElements)({ slot: 'error' })
|
|
485
|
+
], TtCombobox.prototype, "errorElements", void 0);
|
|
486
|
+
__decorate([
|
|
487
|
+
(0, decorators_js_1.queryAll)('tt-option:not([hidden], [disabled])')
|
|
488
|
+
], TtCombobox.prototype, "_visibleOptions", void 0);
|
|
489
|
+
__decorate([
|
|
490
|
+
(0, decorators_js_1.queryAll)('tt-option:not([hidden], .select-all)')
|
|
491
|
+
], TtCombobox.prototype, "_visibleOptionsNotSelectAll", void 0);
|
|
492
|
+
__decorate([
|
|
493
|
+
(0, decorators_js_1.queryAll)('tt-option:not([disabled], .select-all)')
|
|
494
|
+
], TtCombobox.prototype, "_selectableOptions", void 0);
|
|
495
|
+
__decorate([
|
|
496
|
+
(0, decorators_js_1.queryAll)('tt-option:not([disabled], [hidden], .select-all)')
|
|
497
|
+
], TtCombobox.prototype, "_selectableVisibleOptions", void 0);
|
|
498
|
+
__decorate([
|
|
499
|
+
(0, decorators_js_1.query)('input[role="combobox"]')
|
|
500
|
+
], TtCombobox.prototype, "_comboboxInput", void 0);
|
|
501
|
+
__decorate([
|
|
502
|
+
(0, decorators_js_1.query)('button:has(svg)')
|
|
503
|
+
], TtCombobox.prototype, "_chevronButton", void 0);
|
|
504
|
+
__decorate([
|
|
505
|
+
(0, decorators_js_1.property)({ type: (Array), attribute: 'value' })
|
|
506
|
+
], TtCombobox.prototype, "value", void 0);
|
|
507
|
+
//# sourceMappingURL=TtCombobox.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TtCombobox.js","sourceRoot":"","sources":["../../../src/TtCombobox.ts"],"names":[],"mappings":";;;;;;;;;AAAA,6BAAgE;AAChE,qDAA4F;AAC5F,gEAAyD;AACzD,wDAAkD;AAClD,kEAA2D;AAC3D,gEAAyD;AACzD,sDAAgD;AAChD,4CAAsD;AACtD,2CAAqC;AAGrC,MAAa,UAAW,SAAQ,gBAAU;IA2CxC,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC;IAC7B,CAAC;IA2CD,IAAY,cAAc;QACxB,OAAO,CACL,OAAO,CAAC,IAAI,CAAC,2BAA2B,CAAC,MAAM,CAAC;YAChD,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,2BAA2B,CAAC,CAAC,KAAK,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAClG,CAAC;IACJ,CAAC;IAED,IAAc,uBAAuB;QACnC,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;IAChG,CAAC;IAED,IAAc,gBAAgB;QAC5B,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;AAG/B;IADC,IAAA,qCAAqB,EAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAC;2CAC3B;AAGnC;IADC,IAAA,qCAAqB,EAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,2BAA2B,EAAE,CAAC;iDACxC;AAG/B;IADT,IAAA,qCAAqB,EAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;iDACI;AAGnC;IADT,IAAA,wBAAQ,EAAC,qCAAqC,CAAC;mDACJ;AAGlC;IADT,IAAA,wBAAQ,EAAC,sCAAsC,CAAC;+DACO;AAG9C;IADT,IAAA,wBAAQ,EAAC,wCAAwC,CAAC;sDACC;AAG1C;IADT,IAAA,wBAAQ,EAAC,kDAAkD,CAAC;6DACF;AAGjD;IADT,IAAA,qBAAK,EAAC,wBAAwB,CAAC;kDACY;AAGlC;IADT,IAAA,qBAAK,EAAC,iBAAiB,CAAC;kDACoB;AAKtC;IADN,IAAA,wBAAQ,EAAC,EAAE,IAAI,EAAE,CAAA,KAAa,CAAA,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC;yCAC1B","sourcesContent":["import { html, LitElement, nothing, PropertyValues } from 'lit';\nimport { property, query, queryAll, queryAssignedElements, state } from 'lit/decorators.js';\nimport { ifDefined } from 'lit/directives/if-defined.js';\nimport { repeat } from 'lit/directives/repeat.js';\nimport { unsafeHTML } from 'lit/directives/unsafe-html.js';\nimport { unsafeSVG } from 'lit/directives/unsafe-svg.js';\nimport { guard } from 'lit/directives/guard.js';\nimport { alert, chevronDown } from '@triptease/icons';\nimport { styles } from './styles.js';\nimport { TtOption } from './tt-option/TtOption.js';\n\nexport class TtCombobox extends LitElement {\n static styles = styles;\n\n static formAssociated = true;\n\n static shadowRootOptions = {\n ...LitElement.shadowRootOptions,\n delegatesFocus: true,\n };\n\n @property({ type: Boolean })\n multiselect = false;\n\n @property({ type: Boolean })\n disabled = false;\n\n @property({ type: Boolean })\n invalid = false;\n\n @property({ type: Boolean, attribute: 'display-select-all' })\n displaySelectAll = false;\n\n @property({ type: Boolean })\n required = false;\n\n @property({ type: String })\n name = '';\n\n @property({ type: String, attribute: 'aria-labelledby' })\n ariaLabelledby = nothing;\n\n @property({ type: Boolean, attribute: 'hide-caret' })\n hideCaret = false;\n\n @property({ type: String })\n placeholder?: string;\n\n @property({ type: String, attribute: 'select-all-placeholder' })\n selectAllPlaceholder?: string;\n\n @property({ type: Boolean, attribute: 'open-upward' })\n openUpward = false;\n\n get form(): HTMLFormElement | null {\n return this.internals.form;\n }\n\n @state()\n protected _activeOption: number = -1;\n\n @state()\n protected _expanded = false;\n\n @state()\n protected _filter: string = '';\n\n @queryAssignedElements({ slot: 'option', selector: 'option' })\n options!: Array<HTMLOptionElement>;\n\n @queryAssignedElements({ slot: 'option', selector: 'tt-option:not([disabled])' })\n activeOptions!: Array<HTMLOptionElement>;\n\n @queryAssignedElements({ slot: 'error' })\n protected errorElements!: Array<HTMLElement>;\n\n @queryAll('tt-option:not([hidden], [disabled])')\n protected _visibleOptions!: Array<TtOption>;\n\n @queryAll('tt-option:not([hidden], .select-all)')\n protected _visibleOptionsNotSelectAll!: Array<TtOption>;\n\n @queryAll('tt-option:not([disabled], .select-all)')\n protected _selectableOptions!: NodeListOf<TtOption>;\n\n @queryAll('tt-option:not([disabled], [hidden], .select-all)')\n protected _selectableVisibleOptions!: NodeListOf<TtOption>;\n\n @query('input[role=\"combobox\"]')\n protected _comboboxInput!: HTMLInputElement;\n\n @query('button:has(svg)')\n protected _chevronButton!: HTMLButtonElement;\n\n public internals: ReturnType<typeof this.attachInternals>;\n\n @property({ type: Array<string>, attribute: 'value' })\n public value: string[] = [];\n\n private get _isAllSelected(): boolean {\n return (\n Boolean(this._visibleOptionsNotSelectAll.length) &&\n Array.from(this._visibleOptionsNotSelectAll).every((option) => this.value.includes(option.value))\n );\n }\n\n protected get _selectedVisibleOptions(): Array<TtOption> {\n return Array.from(this._visibleOptions).filter((option) => this.value.includes(option.value));\n }\n\n protected get _selectedOptions(): Array<TtOption> {\n return Array.from(this._visibleOptionsNotSelectAll).filter((option) => this.value.includes(option.value));\n }\n\n private _slotObserver: MutationObserver = new MutationObserver((mutations) => {\n mutations.forEach((mutation) => {\n if (mutation.type === 'attributes') {\n this.requestUpdate('options');\n }\n });\n });\n\n constructor() {\n super();\n this.internals = this.attachInternals();\n }\n\n private _handleFocusOut(e: FocusEvent) {\n if (!this.shadowRoot!.contains(e.relatedTarget as Node | null)) {\n this._expanded = false;\n }\n this._filter = '';\n }\n\n private _onFocus() {\n this._comboboxInput.focus();\n }\n\n public connectedCallback() {\n super.connectedCallback();\n\n this.addEventListener('focus', this._onFocus);\n }\n\n public disconnectedCallback() {\n super.disconnectedCallback();\n\n this.removeEventListener('focus', this._onFocus);\n }\n\n protected firstUpdated(changedProperties: PropertyValues) {\n this.internals.setFormValue(JSON.stringify(this.value));\n\n this._reportValidity();\n this._listenForOptionChange();\n\n super.firstUpdated(changedProperties);\n }\n\n protected update(changedProperties: PropertyValues) {\n if (changedProperties.has('value')) {\n this._valueChanged();\n\n if (\n changedProperties.get('value') !== undefined &&\n JSON.stringify(changedProperties.get('value')) !== JSON.stringify(this.value)\n ) {\n this._dispatchSelectedOptions();\n this._reportValidity();\n }\n }\n\n if (changedProperties.has('_expanded') && changedProperties.get('_expanded') && !this._expanded) {\n this.internals.states.add('interacted');\n }\n\n if (changedProperties.has('options')) {\n this.updateComplete.then(() => {\n const selectedAssignedOptions = Array.from(this.options).filter((option) => option.selected);\n this.value = Array.from(new Set([...this.value, ...selectedAssignedOptions.map((option) => option.value!)]));\n this._listenForOptionChange();\n });\n }\n super.update(changedProperties);\n }\n\n private _valueChanged = () => {\n this._selectableOptions.forEach((option) => {\n if (this.value.includes(option.value!)) {\n this._checkOption(option);\n } else {\n this._uncheckOption(option);\n }\n });\n\n this.internals.setFormValue(JSON.stringify(this.value));\n };\n\n private _listenForOptionChange = () => {\n this.options.forEach((option) => {\n this._slotObserver.observe(option, { attributes: true, attributeFilter: ['selected', 'disabled', 'hidden'] });\n });\n };\n\n private _reportValidity() {\n if (this.required && !this.value.length) {\n const errorMessage = this.multiselect ? 'Please select at least one option' : 'Please select an option';\n\n this.internals.setValidity(\n {\n valueMissing: true,\n },\n errorMessage,\n this._comboboxInput\n );\n this.internals.states.add('--invalid');\n } else if (!this.internals.validity.valid) {\n this.internals.setValidity({});\n\n if (this.internals.states.has('--invalid')) {\n this.internals.states.delete('--invalid');\n }\n }\n }\n\n private get labels(): Array<HTMLElement> {\n return <Array<HTMLElement>>[...this.internals.labels];\n }\n\n private get labelContent(): string {\n if (this.ariaLabel !== null) {\n return this.ariaLabel;\n }\n\n return this.labels.map((label) => label.innerText).join(', ');\n }\n\n private _onKeyUp(event: KeyboardEvent) {\n switch (event.key) {\n case 'ArrowDown':\n event.preventDefault();\n if (!this._expanded) {\n this._expanded = true;\n this._activeOption = -1;\n } else {\n this._activeOption = Math.min(this._visibleOptions.length - 1, this._activeOption + 1);\n }\n break;\n case 'ArrowUp':\n event.preventDefault();\n if (this._expanded) {\n this._activeOption = Math.max(0, this._activeOption - 1);\n }\n break;\n case 'Escape':\n event.preventDefault();\n if (this._expanded) {\n this._expanded = false;\n } else if (this._filter !== '') {\n this._filter = '';\n }\n break;\n case 'Enter':\n event.preventDefault();\n if (this._expanded) {\n this._visibleOptions[this._activeOption].click();\n }\n break;\n default:\n break;\n }\n }\n\n private _uncheckOption(option: HTMLElement) {\n if (option.dataset.deselectable !== 'true') return;\n\n option.setAttribute('aria-selected', 'false');\n const checkbox = <HTMLInputElement>option.querySelector('input[type=\"checkbox\"]');\n if (checkbox) {\n checkbox.checked = false;\n }\n }\n\n private _checkOption(option: HTMLElement) {\n if (!this.multiselect) {\n this._selectableOptions.forEach((opt) => {\n this._uncheckOption(opt);\n });\n }\n\n option.setAttribute('aria-selected', 'true');\n const checkbox = <HTMLInputElement>option.querySelector('input[type=\"checkbox\"]');\n if (checkbox) {\n checkbox.checked = true;\n }\n }\n\n private _getActiveOptionId(): string | undefined {\n if (this._activeOption === -1 || this._visibleOptions.length === 0) {\n return undefined;\n }\n\n const option = this._visibleOptions[this._activeOption];\n return option.id;\n }\n\n private _onClick() {\n this._expanded = !this._expanded;\n\n if (this._expanded) {\n (<HTMLElement>this.shadowRoot?.querySelector('input[role=\"combobox\"]'))?.focus();\n }\n }\n\n private _onChevronClick() {\n (<HTMLElement>this.shadowRoot?.querySelector('input[role=\"combobox\"]'))?.focus();\n }\n\n private _onClickOption(event: MouseEvent) {\n event.preventDefault();\n event.stopPropagation();\n\n const option = event.currentTarget as TtOption;\n if (option.disabled) return;\n\n const selectedValue = option.value as string;\n\n if (this.multiselect) {\n if (this.value.includes(selectedValue)) {\n this.value = this.value.filter((value) => value !== selectedValue);\n } else {\n this.value = [...this.value, selectedValue];\n }\n } else {\n this.value = [selectedValue];\n this._expanded = false;\n }\n }\n\n private _onInput(event: Event) {\n const input = event.target as HTMLInputElement;\n const filter = input.value;\n if (filter !== '' && !this._expanded) {\n this._expanded = true;\n }\n this._activeOption = -1;\n this._filter = filter;\n }\n\n private _dispatchSelectedOptions() {\n this.dispatchEvent(\n new Event('change', {\n bubbles: true,\n composed: true,\n })\n );\n }\n\n private _selectAll = (event: MouseEvent) => {\n event.preventDefault();\n event.stopPropagation();\n\n // If filtering, and all visible options are selected, deselect only visible options\n // Else if filtering, select all visible options\n\n if (this._filter !== '' && this._isAllSelected) {\n const selectedVisibleValues = this._selectedVisibleOptions.map((option) => option.value);\n this.value = this.value.filter((value) => !selectedVisibleValues.includes(value));\n } else if (this._filter !== '') {\n this.value = Array.from(\n new Set([...this.value, ...Array.from(this._selectableVisibleOptions).map((option) => option.value)])\n );\n } else if (this.value.length === this._selectableOptions.length) {\n this.value = [];\n } else {\n this.value = Array.from(this._selectableOptions).map((option) => option.value);\n }\n };\n\n private get _isValid(): boolean {\n return this.internals.validity.valid && !this.invalid;\n }\n\n private _renderCombobox() {\n const placeHolderValue = guard(\n [this.placeholder, this.disabled, this.value, this.activeOptions.length, this.selectAllPlaceholder, this._filter],\n () => {\n if (this.placeholder) {\n return this.placeholder;\n }\n\n if (this.disabled) {\n return 'Disabled';\n }\n if (!this.value.length) {\n return 'No options selected';\n }\n if (this.value.length === 1) {\n return Array.from(this._selectableVisibleOptions)\n .find((option) => option.value === this.value[0])\n ?.textContent?.trim();\n }\n\n // Count all selected values, excluding only those that correspond to permanently hidden options\n const permanentlyHiddenValues = Array.from(this.options)\n .filter((option) => option.hidden)\n .map((option) => option.value);\n\n const selectedCount = this.value.filter((val) => !permanentlyHiddenValues.includes(val)).length;\n\n // Only show \"All options selected\" when truly all non-hidden options are selected\n const totalSelectableCount = this.options.length - permanentlyHiddenValues.length;\n if (this._filter === '' && selectedCount === totalSelectableCount && totalSelectableCount > 0) {\n return this.selectAllPlaceholder || 'All options selected';\n }\n\n return `${selectedCount} options selected`;\n }\n );\n\n return html` <input\n type=\"text\"\n id=\"${this.id}\"\n name=\"${this.name}\"\n autocomplete=\"off\"\n aria-label=\"${this.labelContent}\"\n aria-labelledby=\"${this.ariaLabelledby}\"\n role=\"combobox\"\n aria-controls=\"${this.id}-list\"\n aria-expanded=\"${this._expanded}\"\n aria-autocomplete=\"list\"\n aria-haspopup=\"listbox\"\n aria-disabled=\"${this.disabled}\"\n aria-invalid=\"${!this._isValid}\"\n aria-errormessage=\"${!this._isValid ? `error-msg-${this.id}` : nothing}\"\n aria-required=\"${this.required}\"\n ?disabled=${this.disabled}\n aria-activedescendant=\"${ifDefined(this._getActiveOptionId())}\"\n @input=\"${this._onInput}\"\n .value=\"${this._filter}\"\n .placeholder=\"${placeHolderValue}\"\n @focusout=\"${this._handleFocusOut}\"\n part=\"input\"\n class=${this.hideCaret ? 'hide-caret' : ''}\n />`;\n }\n\n private _renderSelectAll = () => {\n if (!this.multiselect || !this.displaySelectAll) {\n return nothing;\n }\n const id = `${this.id}-option-select-all`;\n const active = this._getActiveOptionId() === id;\n const selected = this._isAllSelected;\n\n return html`\n <tt-option\n id=\"${id}\"\n class=\"select-all\"\n ?selected=${selected}\n ?active=${active}\n include-checkbox\n @click=\"${this._selectAll}\"\n exportparts=\"option, checkbox\"\n part=\"option\"\n value=\"select-all\"\n >Select all</tt-option\n >\n `;\n };\n\n private _renderOption(option: HTMLOptionElement) {\n const hidden = Boolean(\n (this._filter !== '' &&\n !option.value.toLowerCase().includes(this._filter.toLowerCase()) &&\n !option.innerText.toLowerCase().includes(this._filter.toLowerCase())) ||\n option.hidden\n );\n\n const id = `${this.id}-option-${option.value}`;\n const active = this._getActiveOptionId() === id;\n const selected = this.value.includes(option.value);\n\n return html`\n <tt-option\n id=\"${id}\"\n value=\"${option.value}\"\n ?selected=${selected}\n ?disabled=${option.disabled}\n ?active=${active}\n ?include-checkbox=${this.multiselect}\n ?hidden=${hidden}\n @click=\"${this._onClickOption}\"\n >\n ${unsafeHTML(option.innerHTML)}\n </tt-option>\n `;\n }\n\n private _renderChevron = () => html`\n <button\n type=\"button\"\n aria-label=\"Expand\"\n @click=\"${this._onChevronClick}\"\n aria-expanded=\"${this._expanded}\"\n aria-controls=\"${this.id}-list\"\n tabindex=\"-1\"\n ?disabled=${this.disabled}\n part=\"arrow\"\n >\n ${unsafeSVG(chevronDown)}\n </button>\n `;\n\n private _hasErrorContent(): boolean {\n return this.errorElements?.length > 0;\n }\n\n render() {\n return html`\n <div\n class=\"tt-combobox-container\"\n @focus=\"${this._onFocus}\"\n @keydown=\"${this._onKeyUp}\"\n @click=\"${this._onClick}\"\n aria-disabled=\"${this.disabled}\"\n part=\"container\"\n >\n <slot name=\"icon\" part=\"icon\"></slot>\n ${this._renderCombobox()} ${this._renderChevron()}\n <ul\n id=\"${this.id}-list\"\n role=\"listbox\"\n aria-multiselectable=\"${this.multiselect}\"\n aria-label=\"${this.labelContent}\"\n part=\"listbox\"\n ?data-open-upward=\"${this.openUpward}\"\n >\n ${this._renderSelectAll()} ${repeat(this.options, (opt) => opt.value, this._renderOption.bind(this))}\n\n <li part=\"no-results\" class=\"no-results\">No results</li>\n </ul>\n </div>\n <slot name=\"option\" @slotchange=${() => this.requestUpdate('options')}></slot>\n <div\n class=\"errormessage\"\n id=\"error-msg-${this.id}\"\n role=\"alert\"\n aria-atomic=\"true\"\n ?data-hidden=\"${!this._hasErrorContent()}\"\n part=\"error\"\n >\n ${unsafeSVG(alert)}\n <slot name=\"error\"></slot>\n </div>\n `;\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'tt-combobox': TtCombobox;\n }\n}\n"]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.TtCombobox = void 0;
|
|
18
|
+
__exportStar(require("./types.js"), exports);
|
|
19
|
+
var tt_combobox_js_1 = require("./tt-combobox.js");
|
|
20
|
+
Object.defineProperty(exports, "TtCombobox", { enumerable: true, get: function () { return tt_combobox_js_1.TtCombobox; } });
|
|
21
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,6CAA2B;AAC3B,mDAA8C;AAArC,4GAAA,UAAU,OAAA","sourcesContent":["export * from './types.js';\nexport { TtCombobox } from './tt-combobox.js';\n"]}
|