@getflip/swirl-components 0.86.0 → 0.87.0
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/components.json +57 -8
- package/dist/cjs/index-506fe4ea.js +4 -8
- package/dist/cjs/loader.cjs.js +1 -1
- package/dist/cjs/swirl-autocomplete.cjs.entry.js +99 -15
- package/dist/cjs/swirl-components.cjs.js +1 -1
- package/dist/cjs/swirl-form-control.cjs.entry.js +1 -1
- package/dist/cjs/{swirl-option-list.cjs.entry.js → swirl-option-list_2.cjs.entry.js} +29 -0
- package/dist/cjs/swirl-select.cjs.entry.js +2 -2
- package/dist/cjs/swirl-text-input.cjs.entry.js +1 -1
- package/dist/collection/assets/pdfjs/pdf.worker.min.js +0 -22
- package/dist/collection/components/swirl-autocomplete/swirl-autocomplete.css +15 -0
- package/dist/collection/components/swirl-autocomplete/swirl-autocomplete.js +155 -26
- package/dist/collection/components/swirl-autocomplete/swirl-autocomplete.spec.js +12 -14
- package/dist/collection/components/swirl-autocomplete/swirl-autocomplete.stories.js +15 -7
- package/dist/collection/components/swirl-form-control/swirl-form-control.css +19 -0
- package/dist/collection/components/swirl-option-list/swirl-option-list.js +5 -0
- package/dist/collection/components/swirl-select/swirl-select.css +2 -1
- package/dist/collection/components/swirl-select/swirl-select.js +1 -1
- package/dist/collection/components/swirl-text-input/swirl-text-input.css +8 -0
- package/dist/collection/components/swirl-text-input/swirl-text-input.stories.js +1 -0
- package/dist/components/assets/pdfjs/pdf.worker.min.js +0 -22
- package/dist/components/swirl-autocomplete.js +142 -38
- package/dist/components/swirl-form-control.js +1 -1
- package/dist/components/swirl-option-list2.js +5 -0
- package/dist/components/swirl-select.js +2 -2
- package/dist/components/swirl-text-input2.js +1 -1
- package/dist/esm/index-99d0060d.js +4 -8
- package/dist/esm/loader.js +1 -1
- package/dist/esm/swirl-autocomplete.entry.js +99 -15
- package/dist/esm/swirl-components.js +1 -1
- package/dist/esm/swirl-form-control.entry.js +1 -1
- package/dist/esm/{swirl-option-list.entry.js → swirl-option-list_2.entry.js} +29 -1
- package/dist/esm/swirl-select.entry.js +2 -2
- package/dist/esm/swirl-text-input.entry.js +1 -1
- package/dist/swirl-components/p-01a47a2e.entry.js +1 -0
- package/dist/swirl-components/p-7dafac36.entry.js +1 -0
- package/dist/swirl-components/p-8153cd85.entry.js +1 -0
- package/dist/swirl-components/p-bf258885.entry.js +1 -0
- package/dist/swirl-components/{p-ce1cd2e1.entry.js → p-e9e6bea8.entry.js} +1 -1
- package/dist/swirl-components/swirl-components.css +1 -1
- package/dist/swirl-components/swirl-components.esm.js +1 -1
- package/dist/types/components/swirl-autocomplete/swirl-autocomplete.d.ts +11 -4
- package/dist/types/components/swirl-autocomplete/swirl-autocomplete.stories.d.ts +7 -0
- package/dist/types/components.d.ts +11 -7
- package/dist/types/index.d.ts +1 -0
- package/package.json +1 -1
- package/vscode-data.json +8 -4
- package/dist/cjs/swirl-tag.cjs.entry.js +0 -30
- package/dist/esm/swirl-tag.entry.js +0 -26
- package/dist/swirl-components/p-18a16156.entry.js +0 -1
- package/dist/swirl-components/p-7521afa2.entry.js +0 -1
- package/dist/swirl-components/p-9c5e2b99.entry.js +0 -1
- package/dist/swirl-components/p-c3d23855.entry.js +0 -1
- package/dist/swirl-components/p-f299ab14.entry.js +0 -1
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
padding-bottom: var(--s-space-8);
|
|
19
19
|
border-radius: var(--s-border-radius-sm);
|
|
20
20
|
background-color: var(--s-surface-overlay-default);
|
|
21
|
+
animation: autocomplete-enter 0.1s;
|
|
21
22
|
box-shadow: var(--s-shadow-level-1);
|
|
22
23
|
}
|
|
23
24
|
|
|
@@ -31,3 +32,17 @@
|
|
|
31
32
|
justify-content: center;
|
|
32
33
|
align-items: center;
|
|
33
34
|
}
|
|
35
|
+
|
|
36
|
+
.autocomplete__multi-select-tags {
|
|
37
|
+
margin-bottom: var(--s-space-4);
|
|
38
|
+
margin-top: var(--swirl-autocomplete-tags-margin-top);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
@keyframes autocomplete-enter {
|
|
42
|
+
from {
|
|
43
|
+
opacity: 0;
|
|
44
|
+
}
|
|
45
|
+
to {
|
|
46
|
+
opacity: 1;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -4,19 +4,57 @@ import classnames from "classnames";
|
|
|
4
4
|
import { debounce } from "../../utils";
|
|
5
5
|
export class SwirlAutocomplete {
|
|
6
6
|
constructor() {
|
|
7
|
-
this.onChange =
|
|
8
|
-
|
|
9
|
-
this.
|
|
10
|
-
|
|
7
|
+
this.onChange = (event) => {
|
|
8
|
+
event.stopPropagation();
|
|
9
|
+
this.updateTerm(event);
|
|
10
|
+
};
|
|
11
|
+
this.updateTerm = debounce(async (event) => {
|
|
12
|
+
this.updateSuggestions(event.detail);
|
|
11
13
|
this.open();
|
|
14
|
+
if (this.multiSelect) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
if (!Boolean(event.detail) || event.detail === "") {
|
|
18
|
+
this.value = undefined;
|
|
19
|
+
this.valueChange.emit(this.value);
|
|
20
|
+
}
|
|
12
21
|
}, 250, false);
|
|
13
|
-
this.onSelect = (event) => {
|
|
14
|
-
|
|
15
|
-
|
|
22
|
+
this.onSelect = async (event) => {
|
|
23
|
+
event.stopPropagation();
|
|
24
|
+
if (this.multiSelect) {
|
|
25
|
+
const selectedItemIds = event.detail;
|
|
26
|
+
const unselectedItemIds = this.suggestions
|
|
27
|
+
.filter((suggestion) => !selectedItemIds.includes(suggestion.id))
|
|
28
|
+
.map((suggestion) => suggestion.id);
|
|
29
|
+
this.value = [
|
|
30
|
+
...this.value.filter((item) => !unselectedItemIds.includes(item.id)),
|
|
31
|
+
...this.suggestions.filter((suggestion) => selectedItemIds.includes(suggestion.id) &&
|
|
32
|
+
!this.value.some((item) => item.id === suggestion.id)),
|
|
33
|
+
];
|
|
16
34
|
this.valueChange.emit(this.value);
|
|
35
|
+
this.inputEl.querySelector("input")?.focus();
|
|
36
|
+
await this.updateSuggestions(this.inputEl.querySelector("input").value);
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
if (Boolean(event.detail[0])) {
|
|
40
|
+
const itemId = event.detail[0];
|
|
41
|
+
const suggestion = this.suggestions.find((suggestion) => suggestion.id === itemId);
|
|
42
|
+
if (!Boolean(suggestion)) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
this.value = suggestion;
|
|
46
|
+
this.valueChange.emit(this.value);
|
|
47
|
+
this.inputEl.querySelector("input")?.focus();
|
|
48
|
+
this.close();
|
|
49
|
+
}
|
|
17
50
|
}
|
|
18
|
-
|
|
19
|
-
|
|
51
|
+
};
|
|
52
|
+
this.onRemoveValue = (value) => {
|
|
53
|
+
if (!Array.isArray(this.value)) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
this.value = this.value.filter((item) => item.id !== value);
|
|
57
|
+
this.valueChange.emit(this.value);
|
|
20
58
|
};
|
|
21
59
|
this.onFocusOut = (event) => {
|
|
22
60
|
const relatedTarget = event.relatedTarget;
|
|
@@ -31,6 +69,7 @@ export class SwirlAutocomplete {
|
|
|
31
69
|
this.onKeyDown = (event) => {
|
|
32
70
|
if (event.code === "Escape") {
|
|
33
71
|
event.preventDefault();
|
|
72
|
+
event.stopPropagation();
|
|
34
73
|
this.inputEl.querySelector("input").focus();
|
|
35
74
|
this.close();
|
|
36
75
|
}
|
|
@@ -51,6 +90,8 @@ export class SwirlAutocomplete {
|
|
|
51
90
|
this.maxLength = undefined;
|
|
52
91
|
this.menuLabel = "Suggestions";
|
|
53
92
|
this.mode = undefined;
|
|
93
|
+
this.multiSelect = undefined;
|
|
94
|
+
this.placeholder = undefined;
|
|
54
95
|
this.required = undefined;
|
|
55
96
|
this.spellCheck = undefined;
|
|
56
97
|
this.swirlAriaDescribedby = undefined;
|
|
@@ -63,6 +104,7 @@ export class SwirlAutocomplete {
|
|
|
63
104
|
componentWillLoad() {
|
|
64
105
|
const index = document.querySelectorAll("swirl-datepicker").length;
|
|
65
106
|
this.id = `autocomplete-${index}`;
|
|
107
|
+
this.handleInitialValue();
|
|
66
108
|
}
|
|
67
109
|
onWindowClick(event) {
|
|
68
110
|
const target = event.target;
|
|
@@ -70,6 +112,9 @@ export class SwirlAutocomplete {
|
|
|
70
112
|
this.close();
|
|
71
113
|
}
|
|
72
114
|
}
|
|
115
|
+
watchMultiSelect() {
|
|
116
|
+
this.handleInitialValue();
|
|
117
|
+
}
|
|
73
118
|
async close() {
|
|
74
119
|
if (!this.active) {
|
|
75
120
|
return;
|
|
@@ -77,6 +122,16 @@ export class SwirlAutocomplete {
|
|
|
77
122
|
if (this.disableAutoUpdate) {
|
|
78
123
|
this.disableAutoUpdate();
|
|
79
124
|
}
|
|
125
|
+
const inputEl = this.inputEl.querySelector("input");
|
|
126
|
+
if (Boolean(inputEl)) {
|
|
127
|
+
if (this.multiSelect) {
|
|
128
|
+
inputEl.value = "";
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
inputEl.value =
|
|
132
|
+
this.value?.label || "";
|
|
133
|
+
}
|
|
134
|
+
}
|
|
80
135
|
this.active = false;
|
|
81
136
|
}
|
|
82
137
|
async open() {
|
|
@@ -89,8 +144,9 @@ export class SwirlAutocomplete {
|
|
|
89
144
|
if (this.disableAutoUpdate) {
|
|
90
145
|
this.disableAutoUpdate();
|
|
91
146
|
}
|
|
92
|
-
this.disableAutoUpdate = autoUpdate(this.inputEl, this.listboxContainerEl, this.reposition.bind(this));
|
|
147
|
+
this.disableAutoUpdate = autoUpdate(this.inputEl, this.listboxContainerEl, this.reposition.bind(this), { animationFrame: true });
|
|
93
148
|
this.listboxContainerEl.scrollTop = 0;
|
|
149
|
+
this.updateSuggestions(this.inputEl.querySelector("input").value);
|
|
94
150
|
});
|
|
95
151
|
}
|
|
96
152
|
async reposition() {
|
|
@@ -103,22 +159,47 @@ export class SwirlAutocomplete {
|
|
|
103
159
|
strategy: "fixed",
|
|
104
160
|
});
|
|
105
161
|
}
|
|
106
|
-
async updateSuggestions() {
|
|
162
|
+
async updateSuggestions(term) {
|
|
107
163
|
this.loading = true;
|
|
108
164
|
this.suggestions = [];
|
|
109
|
-
this.suggestions = await this.generateSuggestions(
|
|
165
|
+
this.suggestions = await this.generateSuggestions(term);
|
|
110
166
|
this.loading = false;
|
|
111
167
|
}
|
|
168
|
+
handleInitialValue() {
|
|
169
|
+
if (this.multiSelect && !Array.isArray(this.value)) {
|
|
170
|
+
this.value = [];
|
|
171
|
+
}
|
|
172
|
+
if (!this.multiSelect && Array.isArray(this.value)) {
|
|
173
|
+
this.value = undefined;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
112
176
|
render() {
|
|
113
177
|
const suggestionsMenuId = `${this.id}-suggestions`;
|
|
178
|
+
const clearable = this.clearable && !this.multiSelect;
|
|
179
|
+
const optionListValue = this.multiSelect
|
|
180
|
+
? this.value.map((item) => item.id)
|
|
181
|
+
: Boolean(this.value)
|
|
182
|
+
? [this.value.id]
|
|
183
|
+
: [];
|
|
184
|
+
const valueLabel = this.multiSelect
|
|
185
|
+
? undefined
|
|
186
|
+
: this.value?.label || "";
|
|
114
187
|
const className = classnames("autocomplete", {
|
|
115
188
|
"autocomplete--inactive": !this.active,
|
|
116
189
|
});
|
|
117
|
-
return (h(Host, null, h("div", { class: className, onFocusout: this.onFocusOut, onKeyDown: this.onKeyDown },
|
|
190
|
+
return (h(Host, null, h("div", { class: className, onFocusout: this.onFocusOut, onKeyDown: this.onKeyDown }, this.multiSelect &&
|
|
191
|
+
Array.isArray(this.value) &&
|
|
192
|
+
this.value.length > 0 && (h("div", { class: "autocomplete__multi-select-tags" }, h("swirl-stack", { orientation: "horizontal", spacing: "8", wrap: true }, this.value.map((item) => {
|
|
193
|
+
return (h("swirl-tag", { key: item.id, label: item.label,
|
|
194
|
+
// eslint-disable-next-line react/jsx-no-bind
|
|
195
|
+
onRemove: () => this.onRemoveValue(item.id), removable: !this.disabled }));
|
|
196
|
+
})))), h("swirl-text-input", { autoSelect: this.autoSelect, class: "autocomplete__input", clearable: clearable, clearButtonLabel: this.clearButtonLabel, disabled: this.disabled, disableDynamicWidth: true, id: this.id, inline: this.inline, invalid: this.invalid, onInputFocus: this.onFocus, onKeyDown: this.onInputKeyDown, onValueChange: this.onChange, maxLength: this.maxLength, mode: this.mode, placeholder: this.placeholder, ref: (el) => (this.inputEl = el), required: this.required, spellCheck: this.spellCheck, swirlAriaAutocomplete: "list", swirlAriaControls: suggestionsMenuId, swirlAriaDescribedby: this.swirlAriaDescribedby, swirlAriaExpanded: String(this.active), swirlRole: "combobox", value: valueLabel }), h("div", { class: "autocomplete__listbox-container", ref: (el) => (this.listboxContainerEl = el), style: {
|
|
118
197
|
top: Boolean(this.position) ? `${this.position?.y}px` : "",
|
|
119
198
|
left: Boolean(this.position) ? `${this.position?.x}px` : "",
|
|
120
199
|
width: `${this.inputEl?.getBoundingClientRect().width + 32}px`,
|
|
121
|
-
} }, this.loading && (h("div", { class: "autocomplete__spinner" }, h("swirl-spinner", null))), this.suggestions.length > 0 && (h("swirl-option-list", { label: this.menuLabel, onValueChange: this.onSelect, optionListId: suggestionsMenuId, ref: (el) => (this.listboxEl = el), value:
|
|
200
|
+
} }, this.loading && (h("div", { class: "autocomplete__spinner" }, h("swirl-spinner", null))), this.suggestions.length > 0 && (h("swirl-option-list", { allowDeselect: this.multiSelect === true, label: this.menuLabel, multiSelect: this.multiSelect, onValueChange: this.onSelect, optionListId: suggestionsMenuId, ref: (el) => (this.listboxEl = el), value: optionListValue }, this.suggestions.map((suggestion) => (h("swirl-option-list-item", { selected: Array.isArray(this.value)
|
|
201
|
+
? this.value.some((item) => item.id === suggestion.id)
|
|
202
|
+
: this.value?.id === suggestion.id, key: suggestion.id, disabled: suggestion.disabled, label: suggestion.label, value: suggestion.id })))))))));
|
|
122
203
|
}
|
|
123
204
|
static get is() { return "swirl-autocomplete"; }
|
|
124
205
|
static get encapsulation() { return "scoped"; }
|
|
@@ -208,8 +289,8 @@ export class SwirlAutocomplete {
|
|
|
208
289
|
"type": "unknown",
|
|
209
290
|
"mutable": true,
|
|
210
291
|
"complexType": {
|
|
211
|
-
"original": "(\n
|
|
212
|
-
"resolved": "(
|
|
292
|
+
"original": "(\n term: string\n ) => Promise<SwirlAutocompleteSuggestion[]>",
|
|
293
|
+
"resolved": "(term: string) => Promise<SwirlAutocompleteSuggestion[]>",
|
|
213
294
|
"references": {
|
|
214
295
|
"Promise": {
|
|
215
296
|
"location": "global"
|
|
@@ -319,6 +400,40 @@ export class SwirlAutocomplete {
|
|
|
319
400
|
"attribute": "mode",
|
|
320
401
|
"reflect": false
|
|
321
402
|
},
|
|
403
|
+
"multiSelect": {
|
|
404
|
+
"type": "boolean",
|
|
405
|
+
"mutable": false,
|
|
406
|
+
"complexType": {
|
|
407
|
+
"original": "boolean",
|
|
408
|
+
"resolved": "boolean",
|
|
409
|
+
"references": {}
|
|
410
|
+
},
|
|
411
|
+
"required": false,
|
|
412
|
+
"optional": true,
|
|
413
|
+
"docs": {
|
|
414
|
+
"tags": [],
|
|
415
|
+
"text": ""
|
|
416
|
+
},
|
|
417
|
+
"attribute": "multi-select",
|
|
418
|
+
"reflect": false
|
|
419
|
+
},
|
|
420
|
+
"placeholder": {
|
|
421
|
+
"type": "string",
|
|
422
|
+
"mutable": false,
|
|
423
|
+
"complexType": {
|
|
424
|
+
"original": "string",
|
|
425
|
+
"resolved": "string",
|
|
426
|
+
"references": {}
|
|
427
|
+
},
|
|
428
|
+
"required": false,
|
|
429
|
+
"optional": true,
|
|
430
|
+
"docs": {
|
|
431
|
+
"tags": [],
|
|
432
|
+
"text": ""
|
|
433
|
+
},
|
|
434
|
+
"attribute": "placeholder",
|
|
435
|
+
"reflect": false
|
|
436
|
+
},
|
|
322
437
|
"required": {
|
|
323
438
|
"type": "boolean",
|
|
324
439
|
"mutable": false,
|
|
@@ -371,21 +486,24 @@ export class SwirlAutocomplete {
|
|
|
371
486
|
"reflect": false
|
|
372
487
|
},
|
|
373
488
|
"value": {
|
|
374
|
-
"type": "
|
|
489
|
+
"type": "unknown",
|
|
375
490
|
"mutable": true,
|
|
376
491
|
"complexType": {
|
|
377
|
-
"original": "
|
|
378
|
-
"resolved": "string",
|
|
379
|
-
"references": {
|
|
492
|
+
"original": "SwirlAutocompleteValue",
|
|
493
|
+
"resolved": "SwirlAutocompleteSuggestion[] | { disabled?: boolean; id: string; label: string; }",
|
|
494
|
+
"references": {
|
|
495
|
+
"SwirlAutocompleteValue": {
|
|
496
|
+
"location": "local",
|
|
497
|
+
"path": "/home/runner/work/swirl/swirl/packages/swirl-components/src/components/swirl-autocomplete/swirl-autocomplete.tsx"
|
|
498
|
+
}
|
|
499
|
+
}
|
|
380
500
|
},
|
|
381
501
|
"required": false,
|
|
382
502
|
"optional": true,
|
|
383
503
|
"docs": {
|
|
384
504
|
"tags": [],
|
|
385
505
|
"text": ""
|
|
386
|
-
}
|
|
387
|
-
"attribute": "value",
|
|
388
|
-
"reflect": true
|
|
506
|
+
}
|
|
389
507
|
}
|
|
390
508
|
};
|
|
391
509
|
}
|
|
@@ -409,13 +527,24 @@ export class SwirlAutocomplete {
|
|
|
409
527
|
"text": ""
|
|
410
528
|
},
|
|
411
529
|
"complexType": {
|
|
412
|
-
"original": "
|
|
413
|
-
"resolved": "string",
|
|
414
|
-
"references": {
|
|
530
|
+
"original": "SwirlAutocompleteValue",
|
|
531
|
+
"resolved": "SwirlAutocompleteSuggestion[] | { disabled?: boolean; id: string; label: string; }",
|
|
532
|
+
"references": {
|
|
533
|
+
"SwirlAutocompleteValue": {
|
|
534
|
+
"location": "local",
|
|
535
|
+
"path": "/home/runner/work/swirl/swirl/packages/swirl-components/src/components/swirl-autocomplete/swirl-autocomplete.tsx"
|
|
536
|
+
}
|
|
537
|
+
}
|
|
415
538
|
}
|
|
416
539
|
}];
|
|
417
540
|
}
|
|
418
541
|
static get elementRef() { return "el"; }
|
|
542
|
+
static get watchers() {
|
|
543
|
+
return [{
|
|
544
|
+
"propName": "multiSelect",
|
|
545
|
+
"methodName": "watchMultiSelect"
|
|
546
|
+
}];
|
|
547
|
+
}
|
|
419
548
|
static get listeners() {
|
|
420
549
|
return [{
|
|
421
550
|
"name": "click",
|
|
@@ -38,12 +38,12 @@ describe("swirl-autocomplete", () => {
|
|
|
38
38
|
expect(page.root).toEqualHtml(`
|
|
39
39
|
<swirl-autocomplete>
|
|
40
40
|
<div class="autocomplete">
|
|
41
|
-
<swirl-text-input class="autocomplete__input" clearable="" clearbuttonlabel="Clear input" disabledynamicwidth="" swirlariaautocomplete="list" swirlariacontrols="autocomplete-0-suggestions" swirlariaexpanded="true" swirlrole="combobox" id="autocomplete-0"></swirl-text-input>
|
|
41
|
+
<swirl-text-input class="autocomplete__input" clearable="" clearbuttonlabel="Clear input" disabledynamicwidth="" swirlariaautocomplete="list" swirlariacontrols="autocomplete-0-suggestions" swirlariaexpanded="true" swirlrole="combobox" id="autocomplete-0" value=""></swirl-text-input>
|
|
42
42
|
<div class="autocomplete__listbox-container" style="width: 32px;">
|
|
43
43
|
<swirl-option-list label="Suggestions" optionlistid="autocomplete-0-suggestions">
|
|
44
|
-
<swirl-option-list-item label="Item #1" value="
|
|
45
|
-
<swirl-option-list-item disabled="" label="Item #2" value="
|
|
46
|
-
<swirl-option-list-item label="Item #3" value="
|
|
44
|
+
<swirl-option-list-item label="Item #1" value="1"></swirl-option-list-item>
|
|
45
|
+
<swirl-option-list-item disabled="" label="Item #2" value="2"></swirl-option-list-item>
|
|
46
|
+
<swirl-option-list-item label="Item #3" value="3"></swirl-option-list-item>
|
|
47
47
|
</swirl-option-list>
|
|
48
48
|
</div>
|
|
49
49
|
</div>
|
|
@@ -61,12 +61,12 @@ describe("swirl-autocomplete", () => {
|
|
|
61
61
|
input.dispatchEvent(new CustomEvent("valueChange", { detail: "#3" }));
|
|
62
62
|
await page.waitForChanges();
|
|
63
63
|
expect(page.root).toEqualHtml(`
|
|
64
|
-
<swirl-autocomplete
|
|
64
|
+
<swirl-autocomplete>
|
|
65
65
|
<div class="autocomplete">
|
|
66
|
-
<swirl-text-input class="autocomplete__input" clearable="" clearbuttonlabel="Clear input" disabledynamicwidth="" swirlariaautocomplete="list" swirlariacontrols="autocomplete-0-suggestions" swirlariaexpanded="true" swirlrole="combobox" id="autocomplete-0" value="
|
|
66
|
+
<swirl-text-input class="autocomplete__input" clearable="" clearbuttonlabel="Clear input" disabledynamicwidth="" swirlariaautocomplete="list" swirlariacontrols="autocomplete-0-suggestions" swirlariaexpanded="true" swirlrole="combobox" id="autocomplete-0" value=""></swirl-text-input>
|
|
67
67
|
<div class="autocomplete__listbox-container" style="width: 32px;">
|
|
68
68
|
<swirl-option-list label="Suggestions" optionlistid="autocomplete-0-suggestions">
|
|
69
|
-
<swirl-option-list-item label="Item #3" value="
|
|
69
|
+
<swirl-option-list-item label="Item #3" value="3"></swirl-option-list-item>
|
|
70
70
|
</swirl-option-list>
|
|
71
71
|
</div>
|
|
72
72
|
</div>
|
|
@@ -84,15 +84,15 @@ describe("swirl-autocomplete", () => {
|
|
|
84
84
|
input.dispatchEvent(new CustomEvent("valueChange", { detail: "#3" }));
|
|
85
85
|
await page.waitForChanges();
|
|
86
86
|
const listbox = page.root.querySelector("swirl-option-list");
|
|
87
|
-
listbox.dispatchEvent(new CustomEvent("valueChange", { detail: ["
|
|
87
|
+
listbox.dispatchEvent(new CustomEvent("valueChange", { detail: ["3"] }));
|
|
88
88
|
await page.waitForChanges();
|
|
89
89
|
expect(page.root).toEqualHtml(`
|
|
90
|
-
<swirl-autocomplete
|
|
90
|
+
<swirl-autocomplete>
|
|
91
91
|
<div class="autocomplete autocomplete--inactive">
|
|
92
92
|
<swirl-text-input class="autocomplete__input" clearable="" clearbuttonlabel="Clear input" disabledynamicwidth="" swirlariaautocomplete="list" swirlariacontrols="autocomplete-0-suggestions" swirlariaexpanded="false" swirlrole="combobox" id="autocomplete-0" value="Item #3"></swirl-text-input>
|
|
93
93
|
<div class="autocomplete__listbox-container" style="width: 32px;">
|
|
94
94
|
<swirl-option-list label="Suggestions" optionlistid="autocomplete-0-suggestions">
|
|
95
|
-
<swirl-option-list-item label="Item #3" selected="" value="
|
|
95
|
+
<swirl-option-list-item label="Item #3" selected="" value="3"></swirl-option-list-item>
|
|
96
96
|
</swirl-option-list>
|
|
97
97
|
</div>
|
|
98
98
|
</div>
|
|
@@ -112,9 +112,7 @@ describe("swirl-autocomplete", () => {
|
|
|
112
112
|
input.dispatchEvent(new CustomEvent("valueChange", { detail: "#3" }));
|
|
113
113
|
await page.waitForChanges();
|
|
114
114
|
const listbox = page.root.querySelector("swirl-option-list");
|
|
115
|
-
listbox.dispatchEvent(new CustomEvent("valueChange", { detail: ["
|
|
116
|
-
expect(spy.mock.calls[0][0].detail).
|
|
117
|
-
input.dispatchEvent(new CustomEvent("valueChange", { detail: "#3" }));
|
|
118
|
-
expect(spy.mock.calls[1][0].detail).toBe("Item #3");
|
|
115
|
+
listbox.dispatchEvent(new CustomEvent("valueChange", { detail: ["3"] }));
|
|
116
|
+
expect(spy.mock.calls[0][0].detail).toEqual({ id: "3", label: "Item #3" });
|
|
119
117
|
});
|
|
120
118
|
});
|
|
@@ -3,6 +3,13 @@ import Docs from "./swirl-autocomplete.mdx";
|
|
|
3
3
|
export default {
|
|
4
4
|
component: "swirl-autocomplete",
|
|
5
5
|
tags: ["autodocs"],
|
|
6
|
+
argTypes: {
|
|
7
|
+
value: {
|
|
8
|
+
control: {
|
|
9
|
+
type: "object",
|
|
10
|
+
},
|
|
11
|
+
},
|
|
12
|
+
},
|
|
6
13
|
parameters: {
|
|
7
14
|
docs: {
|
|
8
15
|
page: Docs,
|
|
@@ -16,16 +23,16 @@ export default {
|
|
|
16
23
|
|
|
17
24
|
const suggestions = [
|
|
18
25
|
{
|
|
19
|
-
id: "1",
|
|
26
|
+
id: "item-1",
|
|
20
27
|
label: "Item #1",
|
|
21
28
|
},
|
|
22
29
|
{
|
|
23
30
|
disabled: true,
|
|
24
|
-
id: "2",
|
|
31
|
+
id: "item-2",
|
|
25
32
|
label: "Item #2",
|
|
26
33
|
},
|
|
27
34
|
{
|
|
28
|
-
id: "3",
|
|
35
|
+
id: "item-3",
|
|
29
36
|
label: "Item #3",
|
|
30
37
|
},
|
|
31
38
|
];
|
|
@@ -49,20 +56,21 @@ export default {
|
|
|
49
56
|
const Template = (args) => {
|
|
50
57
|
const formControl = document.createElement("swirl-form-control");
|
|
51
58
|
const element = generateStoryElement("swirl-autocomplete", args);
|
|
59
|
+
formControl.setAttribute("disabled", args.disabled ? "true" : "false");
|
|
52
60
|
formControl.label = "Autocomplete";
|
|
53
61
|
const suggestions = [
|
|
54
62
|
{
|
|
55
|
-
id: "1",
|
|
63
|
+
id: "item-1",
|
|
56
64
|
label: "Item #1",
|
|
57
65
|
},
|
|
58
66
|
{
|
|
59
67
|
disabled: true,
|
|
60
|
-
id: "2",
|
|
68
|
+
id: "item-2",
|
|
61
69
|
label: "Item #2",
|
|
62
70
|
},
|
|
63
71
|
{
|
|
64
|
-
id: "3",
|
|
65
|
-
label: "Item #3",
|
|
72
|
+
id: "item-3",
|
|
73
|
+
label: "Item #3 with a longer label",
|
|
66
74
|
},
|
|
67
75
|
];
|
|
68
76
|
element.generateSuggestions = async (value) => {
|
|
@@ -8,6 +8,8 @@
|
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
.form-control {
|
|
11
|
+
--swirl-autocomplete-tags-margin-top: var(--s-space-4);
|
|
12
|
+
|
|
11
13
|
display: block;
|
|
12
14
|
width: 100%;
|
|
13
15
|
line-height: var(--s-line-height-sm);
|
|
@@ -59,7 +61,17 @@
|
|
|
59
61
|
}
|
|
60
62
|
}
|
|
61
63
|
|
|
64
|
+
@media (min-width: 992px) and (max-width: 1439px) and (hover: hover),(min-width: 1440px) {
|
|
65
|
+
|
|
66
|
+
.form-control {
|
|
67
|
+
--swirl-text-input-placeholder-size: var(--s-font-size-sm)
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
62
71
|
.form-control--label-position-outside {
|
|
72
|
+
--swirl-text-input-placeholder-size: var(--s-font-size-base);
|
|
73
|
+
--swirl-autocomplete-tags-margin-top: 0;
|
|
74
|
+
|
|
63
75
|
padding-top: calc(var(--s-line-height-sm) + var(--s-space-4));
|
|
64
76
|
}
|
|
65
77
|
|
|
@@ -106,6 +118,13 @@
|
|
|
106
118
|
max-width: calc(100% - 6rem);
|
|
107
119
|
}
|
|
108
120
|
|
|
121
|
+
@media (min-width: 992px) and (max-width: 1439px) and (hover: hover),(min-width: 1440px) {
|
|
122
|
+
|
|
123
|
+
.form-control--label-position-outside {
|
|
124
|
+
--swirl-text-input-placeholder-size: var(--s-font-size-sm)
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
109
128
|
.form-control--invalid.form-control--has-focus:not(.form-control--disabled) .form-control__label {
|
|
110
129
|
border-color: var(--s-border-critical);
|
|
111
130
|
box-shadow: 0 0 0 var(--s-border-width-default) var(--s-border-critical);
|
|
@@ -147,6 +147,11 @@ export class SwirlOptionList {
|
|
|
147
147
|
observeSlotChanges() {
|
|
148
148
|
this.observer = new MutationObserver(() => {
|
|
149
149
|
this.updateItems();
|
|
150
|
+
this.setItemAllowDragState();
|
|
151
|
+
this.setItemDisabledState();
|
|
152
|
+
this.setItemContext();
|
|
153
|
+
this.syncItemsWithValue();
|
|
154
|
+
this.setupDragDrop();
|
|
150
155
|
});
|
|
151
156
|
this.observer.observe(this.listboxEl, { childList: true });
|
|
152
157
|
}
|
|
@@ -127,6 +127,14 @@
|
|
|
127
127
|
-moz-appearance: textfield;
|
|
128
128
|
}
|
|
129
129
|
|
|
130
|
+
.text-input__input::-moz-placeholder {
|
|
131
|
+
font-size: var(--swirl-text-input-placeholder-size);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
.text-input__input::placeholder {
|
|
135
|
+
font-size: var(--swirl-text-input-placeholder-size);
|
|
136
|
+
}
|
|
137
|
+
|
|
130
138
|
@media (min-width: 992px) and (max-width: 1439px) and (hover: hover),(min-width: 1440px) {
|
|
131
139
|
|
|
132
140
|
.text-input__input {
|
|
@@ -14,6 +14,7 @@ const Template = (args) => {
|
|
|
14
14
|
const formControl = document.createElement("swirl-form-control");
|
|
15
15
|
const element = generateStoryElement("swirl-text-input", args);
|
|
16
16
|
formControl.setAttribute("label", "Input");
|
|
17
|
+
formControl.setAttribute("disabled", args.disabled ? "true" : "false");
|
|
17
18
|
formControl.append("\n ", element, "\n");
|
|
18
19
|
return formControl;
|
|
19
20
|
};
|