@six-group/ui-library 0.0.0-insider.7c3e3d8 → 0.0.0-insider.a358260

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. package/dist/cjs/six-checkbox.cjs.entry.js +57 -46
  2. package/dist/cjs/six-checkbox.cjs.entry.js.map +1 -1
  3. package/dist/cjs/six-input.cjs.entry.js +8 -10
  4. package/dist/cjs/six-input.cjs.entry.js.map +1 -1
  5. package/dist/cjs/six-radio.cjs.entry.js +56 -51
  6. package/dist/cjs/six-radio.cjs.entry.js.map +1 -1
  7. package/dist/cjs/six-range.cjs.entry.js +114 -75
  8. package/dist/cjs/six-range.cjs.entry.js.map +1 -1
  9. package/dist/cjs/six-select.cjs.entry.js +298 -239
  10. package/dist/cjs/six-select.cjs.entry.js.map +1 -1
  11. package/dist/cjs/six-textarea.cjs.entry.js +97 -74
  12. package/dist/cjs/six-textarea.cjs.entry.js.map +1 -1
  13. package/dist/collection/components/six-checkbox/six-checkbox.js +62 -49
  14. package/dist/collection/components/six-checkbox/six-checkbox.js.map +1 -1
  15. package/dist/collection/components/six-input/six-input.js +8 -10
  16. package/dist/collection/components/six-input/six-input.js.map +1 -1
  17. package/dist/collection/components/six-radio/six-radio.js +60 -53
  18. package/dist/collection/components/six-radio/six-radio.js.map +1 -1
  19. package/dist/collection/components/six-range/six-range.js +121 -76
  20. package/dist/collection/components/six-range/six-range.js.map +1 -1
  21. package/dist/collection/components/six-select/six-select.js +248 -240
  22. package/dist/collection/components/six-select/six-select.js.map +1 -1
  23. package/dist/collection/components/six-select/util.js +52 -0
  24. package/dist/collection/components/six-select/util.js.map +1 -0
  25. package/dist/collection/components/six-textarea/six-textarea.js +115 -105
  26. package/dist/collection/components/six-textarea/six-textarea.js.map +1 -1
  27. package/dist/components/six-checkbox.js +57 -46
  28. package/dist/components/six-checkbox.js.map +1 -1
  29. package/dist/components/six-input2.js +8 -10
  30. package/dist/components/six-input2.js.map +1 -1
  31. package/dist/components/six-radio.js +56 -51
  32. package/dist/components/six-radio.js.map +1 -1
  33. package/dist/components/six-range.js +114 -75
  34. package/dist/components/six-range.js.map +1 -1
  35. package/dist/components/six-select.js +299 -240
  36. package/dist/components/six-select.js.map +1 -1
  37. package/dist/components/six-textarea.js +97 -74
  38. package/dist/components/six-textarea.js.map +1 -1
  39. package/dist/components.json +30 -22
  40. package/dist/esm/six-checkbox.entry.js +57 -46
  41. package/dist/esm/six-checkbox.entry.js.map +1 -1
  42. package/dist/esm/six-input.entry.js +8 -10
  43. package/dist/esm/six-input.entry.js.map +1 -1
  44. package/dist/esm/six-radio.entry.js +56 -51
  45. package/dist/esm/six-radio.entry.js.map +1 -1
  46. package/dist/esm/six-range.entry.js +114 -75
  47. package/dist/esm/six-range.entry.js.map +1 -1
  48. package/dist/esm/six-select.entry.js +299 -240
  49. package/dist/esm/six-select.entry.js.map +1 -1
  50. package/dist/esm/six-textarea.entry.js +97 -74
  51. package/dist/esm/six-textarea.entry.js.map +1 -1
  52. package/dist/types/components/six-checkbox/six-checkbox.d.ts +21 -17
  53. package/dist/types/components/six-input/six-input.d.ts +1 -1
  54. package/dist/types/components/six-radio/six-radio.d.ts +10 -11
  55. package/dist/types/components/six-range/six-range.d.ts +24 -20
  56. package/dist/types/components/six-select/six-select.d.ts +35 -40
  57. package/dist/types/components/six-select/util.d.ts +7 -0
  58. package/dist/types/components/six-textarea/six-textarea.d.ts +22 -31
  59. package/dist/types/components.d.ts +9 -13
  60. package/dist/ui-library/p-163f2bb0.entry.js +2 -0
  61. package/dist/ui-library/p-163f2bb0.entry.js.map +1 -0
  62. package/dist/ui-library/{p-e9e930d2.entry.js → p-394a2a12.entry.js} +2 -2
  63. package/dist/ui-library/{p-e9e930d2.entry.js.map → p-394a2a12.entry.js.map} +1 -1
  64. package/dist/ui-library/{p-7e0cc4ae.entry.js → p-3c635d0a.entry.js} +2 -2
  65. package/dist/ui-library/p-3c635d0a.entry.js.map +1 -0
  66. package/dist/ui-library/p-5a25d6fb.entry.js +2 -0
  67. package/dist/ui-library/p-5a25d6fb.entry.js.map +1 -0
  68. package/dist/ui-library/{p-90dc6af4.entry.js → p-97cc839c.entry.js} +2 -2
  69. package/dist/ui-library/p-97cc839c.entry.js.map +1 -0
  70. package/dist/ui-library/p-f604e067.entry.js +2 -0
  71. package/dist/ui-library/p-f604e067.entry.js.map +1 -0
  72. package/dist/ui-library/ui-library.esm.js +1 -1
  73. package/package.json +1 -1
  74. package/dist/ui-library/p-0d79b0c6.entry.js +0 -2
  75. package/dist/ui-library/p-0d79b0c6.entry.js.map +0 -1
  76. package/dist/ui-library/p-7e0cc4ae.entry.js.map +0 -1
  77. package/dist/ui-library/p-835c3ff7.entry.js +0 -2
  78. package/dist/ui-library/p-835c3ff7.entry.js.map +0 -1
  79. package/dist/ui-library/p-90dc6af4.entry.js.map +0 -1
  80. package/dist/ui-library/p-edc96efc.entry.js +0 -2
  81. package/dist/ui-library/p-edc96efc.entry.js.map +0 -1
@@ -8,6 +8,58 @@ const formControl = require('./form-control-2c17c573.js');
8
8
  const eventListeners = require('./event-listeners-74715e62.js');
9
9
  const executionControl = require('./execution-control-46f388e0.js');
10
10
 
11
+ function getValue(value, multiple, menuItems) {
12
+ var _a, _b;
13
+ if (multiple) {
14
+ if (Array.isArray(value)) {
15
+ return getSelectedValues(value, menuItems);
16
+ }
17
+ else {
18
+ return getSelectedValuesFromString(value, menuItems);
19
+ }
20
+ }
21
+ return (_b = (_a = getSelectedMenuItem(value, menuItems)) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : '';
22
+ }
23
+ function isValidValue(value, multiple, menuItems) {
24
+ if (value === '') {
25
+ return true;
26
+ }
27
+ if (multiple) {
28
+ if (Array.isArray(value)) {
29
+ if (value.length === 0) {
30
+ return true;
31
+ }
32
+ return getSelectedValues(value, menuItems).length === value.length;
33
+ }
34
+ return getSelectedValuesFromString(value, menuItems).length > 0;
35
+ }
36
+ return getSelectedMenuItem(value, menuItems) != null;
37
+ }
38
+ function valueEquals(a, b) {
39
+ if (Array.isArray(a) && Array.isArray(b)) {
40
+ return a.length === b.length && a.every((element, index) => element === b[index]);
41
+ }
42
+ else if (typeof a === 'string' && typeof b === 'string') {
43
+ return a === b;
44
+ }
45
+ return false;
46
+ }
47
+ function isValueEmpty(value) {
48
+ if (Array.isArray(value)) {
49
+ return value.length === 0;
50
+ }
51
+ return value === '';
52
+ }
53
+ function getSelectedValues(values, menuItems) {
54
+ return menuItems.filter((menuItem) => values.includes(menuItem.value)).map((menuItem) => menuItem.value);
55
+ }
56
+ function getSelectedValuesFromString(value, menuItems) {
57
+ return menuItems.filter((menuItem) => value === menuItem.value).map((menuItem) => menuItem.value);
58
+ }
59
+ function getSelectedMenuItem(value, menuItems) {
60
+ return menuItems.find((item) => value === item.value);
61
+ }
62
+
11
63
  const sixSelectCss = ":host{position:relative;box-sizing:border-box}:host *,:host *:before,:host *:after{box-sizing:inherit}.form-control .form-control__label{display:none}.form-control .form-control__help-text{display:none}.form-control .form-control__error-text{display:none}.form-control--has-label .form-control__label{display:inline-block;color:var(--six-input-label-color);font-weight:var(--six-font-weight-bold);margin-bottom:var(--six-spacing-x-small)}.form-control--has-label .form-control__label__required::after{color:var(--six-color-danger-800);content:\"*\"}.form-control--has-label.form-control--small .form-control__label{font-size:var(--six-input-label-font-size-small)}.form-control--has-label.form-control--medium .form-control__label{font-size:var(--six-input-label-font-size-medium)}.form-control--has-label.form-control--large .form-control_label{font-size:var(--six-input-label-font-size-large)}.form-control--has-help-text .form-control__help-text{display:block;color:var(--six-input-help-text-color);margin-top:var(--six-spacing-x-small)}.form-control--has-help-text .form-control__help-text ::slotted(*){margin-top:var(--six-spacing-xxx-small)}.form-control--has-help-text.form-control--small .form-control__help-text{font-size:var(--six-input-help-text-font-size-small)}.form-control--has-help-text.form-control--medium .form-control__help-text{font-size:var(--six-input-help-text-font-size-medium)}.form-control--has-help-text.form-control--large .form-control__help-text{font-size:var(--six-input-help-text-font-size-large)}.form-control--has-error-text .form-control__error-text{display:block;color:var(--six-color-danger-800);margin-top:var(--six-spacing-xxx-small)}.form-control--has-error-text .form-control__error-text ::slotted(*){margin-top:var(--six-spacing-xxx-small)}.form-control--has-error-text.form-control--small .form-control__error-text{font-size:var(--six-input-help-text-font-size-small)}.form-control--has-error-text.form-control--medium .form-control__error-text{font-size:var(--six-input-help-text-font-size-medium)}.form-control--has-error-text.form-control--large .form-control__error-text{font-size:var(--six-input-help-text-font-size-large)}.form-control--disabled .form-control__help-text{color:var(--six-input-help-text-color-disabled)}.form-control--disabled .form-control__label{color:var(--six-input-label-color-disabled)}.form-control--invalid:not(.form-control--disabled) .form-control__label{color:var(--six-input-label-color)}:host{display:block}.select{display:block}.select__box{display:inline-flex;align-items:center;justify-content:start;position:relative;width:100%;font-family:var(--six-font-family);font-weight:var(--six-input-font-weight);font-size:var(--six-input-font-size-medium);letter-spacing:var(--six-input-letter-spacing);background-color:var(--six-input-background-color);border:solid var(--six-border-width) var(--six-input-border-color);vertical-align:middle;overflow:hidden;transition:var(--six-transition-fast) color, var(--six-transition-fast) border, var(--six-transition-fast) box-shadow;cursor:pointer}.select__box--line{border:none;border-bottom:solid var(--six-border-width) var(--six-input-border-color)}.select__box--autocomplete{border:none;overflow:initial}.select:not(.select--disabled) .select__box:hover{background-color:var(--six-input-background-color-hover);color:var(--six-input-color-hover);border-bottom-color:var(--six-input-border-color-hover)}.select:not(.select--disabled) .select__box:hover:not(.select__box--line){border-color:var(--six-input-border-color-hover)}.select:not(.select--disabled) .select__box:focus{background-color:var(--six-input-background-color-focus);outline:none;color:var(--six-input-color-focus);border-bottom-color:var(--six-input-border-color-focus);box-shadow:0 1px 0 0 var(--six-input-border-color-focus)}.select:not(.select--disabled) .select__box:focus:not(.select__box--line){border-color:var(--six-input-border-color-focus);box-shadow:var(--six-input-focus-shadow)}.select--disabled .select__box{background-color:var(--six-input-background-color-disabled);color:var(--six-input-color-disabled);cursor:not-allowed;outline:none}.select--disabled .select__box:not(.select__box--line){border-color:var(--six-input-border-color-disabled)}.select--disabled .select__tags,.select--disabled .select__clear{pointer-events:none}.select--invalid:not(.select--disabled):not(.select--focused) .select__box{border-bottom-color:var(--six-input-border-color-danger)}.select--invalid:not(.select--disabled):not(.select--focused) .select__box:not(.input--line){border-color:var(--six-input-border-color-danger)}.select__label{flex-shrink:1;flex-grow:1;align-items:center;user-select:none;width:0;scrollbar-width:none;-ms-overflow-style:none;overflow-x:auto;overflow-y:hidden;white-space:nowrap}.select__label::-webkit-scrollbar{width:0;height:0}.select__clear{flex-shrink:0;flex-grow:0;display:inline}.select__icon{flex-shrink:0;flex-grow:0;display:inline;transition:var(--six-transition-medium) transform ease}.select--open .select__icon{transform:rotate(-180deg)}.select--placeholder-visible .select__label{color:var(--six-input-placeholder-color)}.select--disabled.select--placeholder-visible .select__label{color:var(--six-input-placeholder-color-disabled)}.select__tags{display:inline-flex;align-items:center;flex-wrap:wrap;justify-content:left;margin-left:var(--six-spacing-xx-small)}.select__hidden-select{clip:rect(0 0 0 0);clip-path:inset(50%);height:1px;overflow:hidden;position:absolute;white-space:nowrap;width:1px}.select__input{position:absolute;top:0;left:0;width:100%;height:100%}.select--small .select__box{border-radius:var(--six-input-border-radius-small);font-size:var(--six-input-font-size-small);min-height:var(--six-height-small)}.select--small .select__box--line{border:none;border-bottom:solid var(--six-border-width) var(--six-input-border-color)}.select--small .select__label{margin:0 var(--six-input-spacing-small)}.select--small .select__clear{margin-right:var(--six-spacing-xxx-small)}.select--small .select__icon{margin-right:var(--six-spacing-x-small)}.select--small .select__tags{padding-bottom:2px}.select--small .select__tags six-tag{padding-top:2px}.select--small .select__tags six-tag:not(:last-of-type){margin-right:var(--six-spacing-xx-small)}.select--small.select--has-tags .select__label{margin-left:0}.select--medium .select__box{border-radius:var(--six-input-border-radius-medium);font-size:var(--six-input-font-size-medium);min-height:var(--six-height-medium)}.select--medium .select__box--line{border:none;border-bottom:solid var(--six-border-width) var(--six-input-border-color)}.select--medium .select__label{margin:0 var(--six-input-spacing-medium)}.select--medium .select__clear{margin-right:var(--six-spacing-xxx-small)}.select--medium .select__icon{margin-right:var(--six-spacing-x-small)}.select--medium .select__tags{padding-bottom:3px}.select--medium .select__tags six-tag{padding-top:3px}.select--medium .select__tags six-tag:not(:last-of-type){margin-right:var(--six-spacing-xx-small)}.select--medium.select--has-tags .select__label{margin-left:0}.select--large .select__box{border-radius:var(--six-input-border-radius-large);font-size:var(--six-input-font-size-large);min-height:var(--six-height-large)}.select--large .select__box--line{border:none;border-bottom:solid var(--six-border-width) var(--six-input-border-color)}.select--large .select__label{margin:0 var(--six-input-spacing-large)}.select--large .select__clear{margin-right:var(--six-spacing-xxx-small)}.select--large .select__icon{margin-right:var(--six-spacing-x-small)}.select--large .select__tags{padding-bottom:4px}.select--large .select__tags six-tag{padding-top:4px}.select--large .select__tags six-tag:not(:last-of-type){margin-right:var(--six-spacing-xx-small)}.select--large.select--has-tags .select__label{margin-left:0}.select--pill.select--small .select__box{border-radius:var(--six-height-small)}.select--pill.select--medium .select__box{border-radius:var(--six-height-medium)}.select--pill.select--large .select__box{border-radius:var(--six-height-large)}.select__menu{max-width:50vw;width:fit-content}.select__menu--filtered{width:100% !important}.select__menu--hidden{display:none}six-icon-button::part(base){padding-top:0;padding-bottom:0}";
12
64
 
13
65
  let id = 0;
@@ -21,9 +73,120 @@ const SixSelect = class {
21
73
  this.labelId = `select-label-${id}`;
22
74
  this.helpTextId = `select-help-text-${id}`;
23
75
  this.errorTextId = `select-error-text-${id}`;
76
+ this.touched = false;
24
77
  this.customErrorText = '';
25
78
  this.customValidation = false;
26
79
  this.eventListeners = new eventListeners.EventListeners();
80
+ this.handleBlur = () => {
81
+ this.hasFocus = false;
82
+ this.sixBlur.emit();
83
+ };
84
+ this.handleFocus = () => {
85
+ this.hasFocus = true;
86
+ this.sixFocus.emit();
87
+ };
88
+ this.handleInvalid = () => {
89
+ this.invalid = true;
90
+ };
91
+ this.handleClearClick = (event) => {
92
+ event.stopPropagation();
93
+ this.clearValues();
94
+ };
95
+ this.handleSelectAll = (event) => {
96
+ const nonFilteredItems = this.getItems().filter((item) => item.style.display !== 'none');
97
+ const keyName = event.key;
98
+ const keyCode = event.code;
99
+ if (keyName === 'Control') {
100
+ return;
101
+ }
102
+ if (this.isOpen && this.multiple && keyCode === 'KeyA' && event.ctrlKey) {
103
+ event.preventDefault();
104
+ const hasDeselectedOptions = nonFilteredItems.some((opt) => !opt.disabled && !opt.checked);
105
+ nonFilteredItems
106
+ .filter((option) => !option.disabled)
107
+ .forEach((option) => (option.checked = hasDeselectedOptions));
108
+ const checkedItems = nonFilteredItems.filter((option) => option.checked).map((option) => option.value);
109
+ this.value = hasDeselectedOptions ? checkedItems : [];
110
+ }
111
+ };
112
+ this.handleKeyDown = async (event) => {
113
+ var _a;
114
+ const target = event.target;
115
+ const items = this.getItems();
116
+ const firstItem = items[0];
117
+ const lastItem = items[items.length - 1];
118
+ // Ignore key presses on tags
119
+ if (target.tagName.toLowerCase() === 'six-tag') {
120
+ return;
121
+ }
122
+ // Tabbing out of the control closes it
123
+ if (event.key === 'Tab') {
124
+ if (this.isOpen && this.dropdown != null) {
125
+ await this.dropdown.hide();
126
+ }
127
+ return;
128
+ }
129
+ // Up/down opens the menu
130
+ if (['ArrowDown', 'ArrowUp'].includes(event.key)) {
131
+ event.preventDefault();
132
+ // Show the menu if it's not already open
133
+ if (!this.isOpen && this.dropdown != null) {
134
+ await this.dropdown.show();
135
+ }
136
+ // Focus on a menu item
137
+ if (event.key === 'ArrowDown' && firstItem) {
138
+ firstItem.setFocus();
139
+ }
140
+ else if (event.key === 'ArrowUp' && lastItem) {
141
+ lastItem.setFocus();
142
+ }
143
+ }
144
+ // All other keys open the menu and initiate type to select
145
+ if (!this.isOpen && this.dropdown != null) {
146
+ event.stopPropagation();
147
+ event.preventDefault();
148
+ await this.dropdown.show();
149
+ await ((_a = this.menu) === null || _a === void 0 ? void 0 : _a.typeToSelect(event.key));
150
+ }
151
+ };
152
+ this.handleLabelClick = () => {
153
+ var _a;
154
+ (_a = this.box) === null || _a === void 0 ? void 0 : _a.focus();
155
+ };
156
+ this.handleMenuShow = (event) => {
157
+ var _a;
158
+ if (this.disabled) {
159
+ event.preventDefault();
160
+ return;
161
+ }
162
+ this.resizeMenu();
163
+ (_a = this.resizeObserver) === null || _a === void 0 ? void 0 : _a.observe(this.host);
164
+ this.isOpen = true;
165
+ };
166
+ this.handleMenuHide = () => {
167
+ var _a;
168
+ (_a = this.resizeObserver) === null || _a === void 0 ? void 0 : _a.unobserve(this.host);
169
+ this.isOpen = false;
170
+ };
171
+ this.handleSlotChange = () => {
172
+ this.hasHelpTextSlot = slot.hasSlot(this.host, 'help-text');
173
+ this.hasErrorTextSlot = slot.hasSlot(this.host, 'error-text');
174
+ this.hasLabelSlot = slot.hasSlot(this.host, 'label');
175
+ this.update();
176
+ };
177
+ this.handleTagInteraction = (event) => {
178
+ // Don't toggle the menu when a tag's clear button is activated
179
+ const path = event.composedPath();
180
+ const clearButton = path.find((el) => {
181
+ if (el instanceof HTMLElement) {
182
+ const element = el;
183
+ return element.classList.contains('tag__clear');
184
+ }
185
+ });
186
+ if (clearButton) {
187
+ event.stopPropagation();
188
+ }
189
+ };
27
190
  this.hasFocus = false;
28
191
  this.hasHelpTextSlot = false;
29
192
  this.hasErrorTextSlot = false;
@@ -59,7 +222,7 @@ const SixSelect = class {
59
222
  this.defaultValue = undefined;
60
223
  }
61
224
  handleDisabledChange() {
62
- if (this.disabled && this.isOpen) {
225
+ if (this.disabled && this.isOpen && this.dropdown != null) {
63
226
  this.dropdown.hide();
64
227
  }
65
228
  }
@@ -67,94 +230,159 @@ const SixSelect = class {
67
230
  this.handleSlotChange();
68
231
  }
69
232
  handleMultipleChange() {
70
- // Cast to array | string based on `this.multiple`
71
- const value = this.getValueAsArray();
72
- this.value = this.multiple ? value : value[0] || '';
73
- this.syncItemsFromValue();
233
+ this.update();
234
+ }
235
+ handleValueChange(newValue, oldValue) {
236
+ var _a;
237
+ let items = (_a = this.options) !== null && _a !== void 0 ? _a : this.getItems();
238
+ // normalize invalid values. This will re-trigger this watch handler
239
+ if (!isValidValue(newValue, this.multiple, items)) {
240
+ this.value = getValue(newValue, this.multiple, items);
241
+ return;
242
+ }
243
+ // avoid re-triggering if old and new values are equal. Needed because
244
+ // watch does a shallow comparison only.
245
+ if (valueEquals(getValue(oldValue, this.multiple, items), getValue(newValue, this.multiple, items))) {
246
+ return;
247
+ }
248
+ this.update();
249
+ this.sixChange.emit({ value: this.value, isSelected: true });
74
250
  }
75
- handleValueChange() {
76
- this.syncItemsFromValue();
77
- if (this.input) {
78
- this.sixChange.emit({ value: this.value, isSelected: true });
251
+ update() {
252
+ var _a;
253
+ const items = this.getItems();
254
+ this.value = getValue(this.value, this.multiple, (_a = this.options) !== null && _a !== void 0 ? _a : items);
255
+ if (!Array.isArray(this.value)) {
256
+ // Sync checked states
257
+ items.forEach((item) => (item.checked = false));
258
+ const item = items.find((item) => this.value.includes(item.value));
259
+ if (item != null) {
260
+ item.checked = true;
261
+ }
262
+ // Sync input element content
263
+ this.displayLabel = this.extractLabelForSelectedItem([this.value], items);
264
+ this.displayTags = [];
265
+ const hasSelection = !isValueEmpty(this.value);
266
+ if (hasSelection) {
267
+ this.touched = true;
268
+ }
269
+ if (this.inputElement && this.touched) {
270
+ if (!this.autocomplete) {
271
+ this.inputElement.value = hasSelection ? this.displayLabel : '';
272
+ }
273
+ else if (hasSelection) {
274
+ this.inputElement.value = this.value;
275
+ }
276
+ this.inputElement.checkValidity().then((valid) => (this.invalid = !valid));
277
+ }
278
+ }
279
+ else {
280
+ // Sync checked states
281
+ items.forEach((item) => (item.checked = this.value.includes(item.value)));
282
+ // Sync display label
283
+ const checkedItems = [];
284
+ this.value.forEach((val) => items.map((item) => (item.value === val ? checkedItems.push(item) : null)));
285
+ this.displayTags = checkedItems.map((item) => {
286
+ return (index.h("six-tag", { exportparts: "base:tag", type: "primary", size: this.size, pill: this.pill, clearable: true, onClick: this.handleTagInteraction, onKeyDown: this.handleTagInteraction, "onSix-tag-clear": (event) => {
287
+ event.stopPropagation();
288
+ if (!this.disabled) {
289
+ this.toggleItem(item);
290
+ }
291
+ } }, this.getItemLabel(item)));
292
+ });
293
+ if (this.maxTagsVisible > 0 && this.displayTags.length > this.maxTagsVisible) {
294
+ const total = this.displayTags.length;
295
+ this.displayLabel = '';
296
+ this.displayTags = this.displayTags.slice(0, this.maxTagsVisible);
297
+ this.displayTags.push(index.h("six-tag", { exportparts: "base:tag", type: "info", size: this.size }, "+", total - this.maxTagsVisible));
298
+ }
299
+ // Sync input element content
300
+ const hasSelection = !isValueEmpty(this.value);
301
+ if (hasSelection) {
302
+ this.touched = true;
303
+ }
304
+ if (this.inputElement && this.touched) {
305
+ if (!this.autocomplete) {
306
+ this.inputElement.value = hasSelection ? this.displayLabel : '';
307
+ }
308
+ else if (hasSelection) {
309
+ this.inputElement.value = this.value.join(',');
310
+ }
311
+ this.inputElement.checkValidity().then((valid) => (this.invalid = !valid));
312
+ }
79
313
  }
80
314
  }
81
315
  connectedCallback() {
316
+ var _a;
82
317
  if (this.virtualScroll && this.options === null) {
83
318
  console.error('Options must be defined when using virtual scrolling');
84
319
  }
85
- this.handleBlur = this.handleBlur.bind(this);
86
- this.handleFocus = this.handleFocus.bind(this);
87
- this.handleClearClick = this.handleClearClick.bind(this);
88
- this.handleKeyDown = this.handleKeyDown.bind(this);
89
- this.handleSelectAll = this.handleSelectAll.bind(this);
90
- this.handleLabelClick = this.handleLabelClick.bind(this);
91
- this.handleMenuHide = this.handleMenuHide.bind(this);
92
- this.handleMenuShow = this.handleMenuShow.bind(this);
93
- this.handleMenuSelect = this.handleMenuSelect.bind(this);
94
- this.handleSlotChange = this.handleSlotChange.bind(this);
95
- this.handleInvalid = this.handleInvalid.bind(this);
96
- this.handleTagInteraction = this.handleTagInteraction.bind(this);
97
- this.host.shadowRoot.addEventListener('slotchange', this.handleSlotChange);
320
+ (_a = this.host.shadowRoot) === null || _a === void 0 ? void 0 : _a.addEventListener('slotchange', this.handleSlotChange);
98
321
  }
99
322
  componentWillLoad() {
100
323
  this.handleSlotChange();
101
- if (this.multiple && this.value) {
102
- this.value = this.getValueAsArray();
103
- }
104
324
  }
105
325
  componentDidLoad() {
326
+ const inputElement = this.inputElement;
327
+ if (inputElement == null) {
328
+ return;
329
+ }
106
330
  this.resizeObserver = new ResizeObserver(() => this.resizeMenu());
107
- // We need to do an initial sync after the component has rendered, so this will suppress the re-render warning
108
- requestAnimationFrame(() => this.syncItemsFromValue());
109
- this.eventListeners.add(this.input, 'invalid', async (event) => {
110
- if (this.customValidation || (!this.hasErrorTextSlot && !this.errorText && !this.customErrorText)) {
111
- this.customErrorText = await this.input.getValidationMessage();
331
+ this.eventListeners.add(inputElement, 'invalid', async (event) => {
332
+ if (this.customValidation || (!this.hasErrorTextSlot && this.errorText === '' && this.customErrorText === '')) {
333
+ this.customErrorText = await inputElement.getValidationMessage();
112
334
  }
113
335
  event.preventDefault();
114
336
  });
115
- this.eventListeners.add(this.input, 'six-input-input', executionControl.debounce((event) => {
116
- const enteredValue = this.input.value;
337
+ this.eventListeners.add(inputElement, 'six-input-input', executionControl.debounce((event) => {
338
+ const enteredValue = inputElement.value;
117
339
  this.clearValues();
118
340
  this.sixChange.emit({ value: enteredValue, isSelected: false });
119
341
  event.stopPropagation();
120
342
  }, this.inputDebounce));
121
- this.input.value = this.hasSelection() ? this.displayLabel : '';
122
343
  }
123
344
  disconnectedCallback() {
124
- this.host.shadowRoot.removeEventListener('slotchange', this.handleSlotChange);
345
+ var _a;
346
+ (_a = this.host.shadowRoot) === null || _a === void 0 ? void 0 : _a.removeEventListener('slotchange', this.handleSlotChange);
125
347
  this.eventListeners.removeAll();
126
348
  }
127
349
  /** Checks for validity and shows the browser's validation message if the control is invalid. */
128
350
  async reportValidity() {
129
- return this.input.reportValidity();
351
+ var _a;
352
+ return (_a = this.inputElement) === null || _a === void 0 ? void 0 : _a.reportValidity();
130
353
  }
131
354
  /** Checks for validity. */
132
355
  async checkValidity() {
133
- return this.input.isValid();
356
+ var _a;
357
+ return (_a = this.inputElement) === null || _a === void 0 ? void 0 : _a.isValid();
134
358
  }
135
359
  /** Sets a custom validation message. If `message` is not empty, the field will be considered invalid. */
136
360
  async setCustomValidity(message) {
137
361
  this.customErrorText = '';
138
362
  this.customValidation = message !== '';
139
- this.input.setCustomValidity(message);
140
- this.invalid = !this.input.checkValidity();
363
+ if (this.inputElement != null) {
364
+ await this.inputElement.setCustomValidity(message);
365
+ this.invalid = !(await this.inputElement.checkValidity());
366
+ }
141
367
  }
142
368
  /** Resets the formcontrol */
143
369
  async reset() {
370
+ var _a;
144
371
  this.clearValues();
145
372
  this.customErrorText = '';
146
373
  this.customValidation = false;
147
- this.input.setCustomValidity('');
374
+ await ((_a = this.inputElement) === null || _a === void 0 ? void 0 : _a.setCustomValidity(''));
148
375
  this.invalid = false;
149
376
  }
150
377
  getItemLabel(item) {
151
- const slot$1 = item.shadowRoot.querySelector('slot:not([name])');
152
- if (slot$1) {
378
+ var _a, _b;
379
+ const slot$1 = (_a = item.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector('slot:not([name])');
380
+ if (slot$1 != null) {
153
381
  return slot.getTextContent(slot$1);
154
382
  }
155
383
  else {
156
384
  // bugfix/COMSLI-203-six-select-value-is-not-updated-if-the-slot-is-changed
157
- return item.textContent;
385
+ return (_b = item.textContent) !== null && _b !== void 0 ? _b : '';
158
386
  }
159
387
  }
160
388
  getItems() {
@@ -166,192 +394,18 @@ const SixSelect = class {
166
394
  hasMenuItems() {
167
395
  return this.getItems().length > 0;
168
396
  }
169
- getValueAsStringArray() {
170
- const values = this.getValueAsArray();
171
- // enforce that the values are converted to 'string' before the value is compared
172
- return values.map(String);
173
- }
174
- getValueAsArray() {
175
- return Array.isArray(this.value) ? this.value : [this.value];
176
- }
177
- handleBlur() {
178
- this.hasFocus = false;
179
- this.sixBlur.emit();
180
- }
181
- handleFocus() {
182
- this.hasFocus = true;
183
- this.sixFocus.emit();
184
- }
185
- handleInvalid() {
186
- this.invalid = true;
187
- }
188
- handleClearClick(event) {
189
- event.stopPropagation();
190
- this.clearValues();
191
- }
192
397
  clearValues() {
193
398
  var _a;
194
399
  this.value = (_a = this.defaultValue) !== null && _a !== void 0 ? _a : (this.multiple ? [] : '');
195
- this.syncItemsFromValue();
196
- }
197
- handleSelectAll(event) {
198
- const nonFilteredItems = this.getItems().filter((item) => item.style.display !== 'none');
199
- const keyName = event.key;
200
- const keyCode = event.code;
201
- if (keyName === 'Control') {
202
- return;
203
- }
204
- if (this.isOpen && this.multiple && keyCode === 'KeyA' && event.ctrlKey) {
205
- event.preventDefault();
206
- const hasDeselectedOptions = nonFilteredItems.some((opt) => !opt.disabled && !opt.checked);
207
- nonFilteredItems
208
- .filter((option) => !option.disabled)
209
- .forEach((option) => (option.checked = hasDeselectedOptions));
210
- const checkedItems = nonFilteredItems.filter((option) => option.checked).map((option) => option.value);
211
- this.value = hasDeselectedOptions ? checkedItems : [];
212
- }
213
- }
214
- handleKeyDown(event) {
215
- const target = event.target;
216
- const items = this.getItems();
217
- const firstItem = items[0];
218
- const lastItem = items[items.length - 1];
219
- // Ignore key presses on tags
220
- if (target.tagName.toLowerCase() === 'six-tag') {
221
- return;
222
- }
223
- // Tabbing out of the control closes it
224
- if (event.key === 'Tab') {
225
- if (this.isOpen) {
226
- this.dropdown.hide();
227
- }
228
- return;
229
- }
230
- // Up/down opens the menu
231
- if (['ArrowDown', 'ArrowUp'].includes(event.key)) {
232
- event.preventDefault();
233
- // Show the menu if it's not already open
234
- if (!this.isOpen) {
235
- this.dropdown.show();
236
- }
237
- // Focus on a menu item
238
- if (event.key === 'ArrowDown' && firstItem) {
239
- firstItem.setFocus();
240
- return;
241
- }
242
- if (event.key === 'ArrowUp' && lastItem) {
243
- lastItem.setFocus();
244
- return;
245
- }
246
- }
247
- // All other keys open the menu and initiate type to select
248
- if (!this.isOpen) {
249
- event.stopPropagation();
250
- event.preventDefault();
251
- this.dropdown.show();
252
- this.menu.typeToSelect(event.key);
253
- }
254
- }
255
- handleLabelClick() {
256
- this.box.focus();
257
- }
258
- handleMenuSelect(event) {
259
- const item = event.detail.item;
260
- if (this.multiple) {
261
- if (this.value == null || this.value === '') {
262
- this.value = [];
263
- }
264
- else if (!Array.isArray(this.value)) {
265
- this.value = [this.value];
266
- }
267
- this.value = this.value.includes(item.value)
268
- ? this.value.filter((v) => v !== item.value)
269
- : [...this.value, item.value];
270
- }
271
- else {
272
- this.value = item.value;
273
- }
274
- this.syncItemsFromValue();
400
+ this.update();
275
401
  }
276
- handleMenuShow(event) {
277
- if (this.disabled) {
278
- event.preventDefault();
402
+ async resizeMenu() {
403
+ if (this.menu == null || this.box == null) {
279
404
  return;
280
405
  }
281
- this.resizeMenu();
282
- this.resizeObserver.observe(this.host);
283
- this.isOpen = true;
284
- }
285
- handleMenuHide() {
286
- this.resizeObserver.unobserve(this.host);
287
- this.isOpen = false;
288
- }
289
- handleSlotChange() {
290
- this.hasHelpTextSlot = slot.hasSlot(this.host, 'help-text');
291
- this.hasErrorTextSlot = slot.hasSlot(this.host, 'error-text');
292
- this.hasLabelSlot = slot.hasSlot(this.host, 'label');
293
- this.syncItemsFromValue();
294
- }
295
- handleTagInteraction(event) {
296
- // Don't toggle the menu when a tag's clear button is activated
297
- const path = event.composedPath();
298
- const clearButton = path.find((el) => {
299
- if (el instanceof HTMLElement) {
300
- const element = el;
301
- return element.classList.contains('tag__clear');
302
- }
303
- });
304
- if (clearButton) {
305
- event.stopPropagation();
306
- }
307
- }
308
- resizeMenu() {
309
406
  this.menu.style.minWidth = `${this.box.clientWidth}px`;
310
407
  if (this.dropdown) {
311
- this.dropdown.reposition();
312
- }
313
- }
314
- syncItemsFromValue() {
315
- const items = this.getItems();
316
- const value = this.getValueAsStringArray();
317
- // Sync checked states
318
- items.forEach((item) => (item.checked = value.includes(item.value)));
319
- // Sync display label
320
- if (this.multiple) {
321
- const checkedItems = [];
322
- value.forEach((val) => items.map((item) => (item.value === val ? checkedItems.push(item) : null)));
323
- this.displayTags = checkedItems.map((item) => {
324
- return (index.h("six-tag", { exportparts: "base:tag", type: "primary", size: this.size, pill: this.pill, clearable: true, onClick: this.handleTagInteraction, onKeyDown: this.handleTagInteraction, "onSix-tag-clear": (event) => {
325
- event.stopPropagation();
326
- if (!this.disabled) {
327
- item.checked = false;
328
- this.syncValueFromItems();
329
- }
330
- } }, this.getItemLabel(item)));
331
- });
332
- if (this.maxTagsVisible > 0 && this.displayTags.length > this.maxTagsVisible) {
333
- const total = this.displayTags.length;
334
- this.displayLabel = '';
335
- this.displayTags = this.displayTags.slice(0, this.maxTagsVisible);
336
- this.displayTags.push(index.h("six-tag", { exportparts: "base:tag", type: "info", size: this.size }, "+", total - this.maxTagsVisible));
337
- }
338
- }
339
- else {
340
- this.displayLabel = this.extractLabelForSelectedItem(value, items);
341
- this.displayTags = [];
342
- }
343
- const hasSelection = this.hasSelection();
344
- if (hasSelection) {
345
- this.touched = true;
346
- }
347
- if (this.input && this.touched) {
348
- if (!this.autocomplete) {
349
- this.input.value = hasSelection ? this.displayLabel : '';
350
- }
351
- else if (hasSelection) {
352
- this.input.value = Array.isArray(this.value) ? this.value.join(',') : this.value;
353
- }
354
- this.invalid = !this.input.checkValidity();
408
+ await this.dropdown.reposition();
355
409
  }
356
410
  }
357
411
  extractLabelForSelectedItem(value, items) {
@@ -365,23 +419,34 @@ const SixSelect = class {
365
419
  const checkedItem = items.find((item) => item.value === value[0]);
366
420
  return checkedItem ? this.getItemLabel(checkedItem) : '';
367
421
  }
368
- syncValueFromItems() {
369
- const items = this.getItems();
370
- const checkedItems = items.filter((item) => item.checked);
371
- const checkedValues = checkedItems.map((item) => item.value);
372
- this.value = this.multiple
373
- ? this.getValueAsStringArray().filter((val) => checkedValues.includes(val))
374
- : checkedValues.length > 0
375
- ? checkedValues[0]
376
- : '';
422
+ toggleItem(item) {
423
+ var _a;
424
+ const value = getValue(this.value, this.multiple, (_a = this.options) !== null && _a !== void 0 ? _a : this.getItems());
425
+ if (Array.isArray(value)) {
426
+ const itemFound = value.find((v) => v === item.value);
427
+ if (itemFound == null) {
428
+ this.value = [...this.value, item.value];
429
+ }
430
+ else {
431
+ this.value = value.filter((v) => v !== item.value);
432
+ }
433
+ }
434
+ else {
435
+ if (item.value === value) {
436
+ this.value = '';
437
+ }
438
+ else {
439
+ this.value = item.value;
440
+ }
441
+ }
377
442
  }
378
443
  displayError() {
379
444
  return this.invalid && (!this.errorOnBlur || (!this.hasFocus && !this.isOpen));
380
445
  }
381
446
  render() {
382
447
  var _a;
383
- const hasSelection = this.hasSelection();
384
- return (index.h(formControl.FormControl, { inputId: this.inputId, label: this.label, labelId: this.labelId, hasLabelSlot: this.hasLabelSlot, helpTextId: this.helpTextId, helpText: this.helpText, hasHelpTextSlot: this.hasHelpTextSlot, errorTextId: this.errorTextId, errorText: this.customErrorText ? this.customErrorText : this.errorText, hasErrorTextSlot: this.hasErrorTextSlot, size: this.size, onLabelClick: this.handleLabelClick, disabled: this.disabled, required: this.required, displayError: this.displayError() }, index.h("six-dropdown", { part: "base", ref: (el) => (this.dropdown = el), hoist: this.hoist, closeOnSelect: !this.multiple, containingElement: this.host, disableHideOnEnterAndSpace: this.autocomplete, class: {
448
+ const hasSelection = !isValueEmpty(this.value);
449
+ return (index.h(formControl.FormControl, { inputId: this.inputId, label: this.label, labelId: this.labelId, hasLabelSlot: this.hasLabelSlot, helpTextId: this.helpTextId, helpText: this.helpText, hasHelpTextSlot: this.hasHelpTextSlot, errorTextId: this.errorTextId, errorText: this.customErrorText != null ? this.customErrorText : this.errorText, hasErrorTextSlot: this.hasErrorTextSlot, size: this.size, onLabelClick: this.handleLabelClick, disabled: this.disabled, required: this.required, displayError: this.displayError() }, index.h("six-dropdown", { part: "base", ref: (el) => (this.dropdown = el), hoist: this.hoist, closeOnSelect: !this.multiple, containingElement: this.host, disableHideOnEnterAndSpace: this.autocomplete, class: {
385
450
  select: true,
386
451
  'select--open': this.isOpen,
387
452
  'select--empty': ((_a = this.value) === null || _a === void 0 ? void 0 : _a.length) === 0,
@@ -400,20 +465,14 @@ const SixSelect = class {
400
465
  select__box: true,
401
466
  'select__box--line': this.line,
402
467
  'select__box--autocomplete': this.autocomplete,
403
- }, role: "combobox", "aria-labelledby": this.labelId, "aria-describedby": this.helpTextId, "aria-haspopup": "true", "aria-expanded": this.isOpen ? 'true' : 'false', tabIndex: this.disabled ? -1 : 0, onBlur: this.handleBlur, onFocus: this.handleFocus, onKeyDown: this.handleKeyDown }, index.h("span", { class: "select__label" }, this.displayTags.length ? (index.h("span", { part: "tags", class: "select__tags" }, this.displayTags)) : (this.displayLabel || this.placeholder)), this.clearable && hasSelection && (index.h("six-icon-button", { exportparts: "base:clear-button", class: "select__clear", name: "clear", size: "small", onClick: this.handleClearClick, tabindex: "-1" })), this.hasMenuItems() && (index.h("span", { part: "icon", class: "select__icon" }, index.h("six-icon", { size: "medium" }, "expand_more"))), index.h("six-input", { ref: (el) => (this.input = el), class: {
468
+ }, role: "combobox", "aria-labelledby": this.labelId, "aria-describedby": this.helpTextId, "aria-haspopup": "true", "aria-expanded": this.isOpen ? 'true' : 'false', tabIndex: this.disabled ? -1 : 0, onBlur: this.handleBlur, onFocus: this.handleFocus, onKeyDown: this.handleKeyDown }, index.h("span", { class: "select__label" }, this.displayTags.length ? (index.h("span", { part: "tags", class: "select__tags" }, this.displayTags)) : (this.displayLabel || this.placeholder)), this.clearable && hasSelection && (index.h("six-icon-button", { exportparts: "base:clear-button", class: "select__clear", name: "clear", size: "small", onClick: this.handleClearClick, tabindex: "-1" })), this.hasMenuItems() && (index.h("span", { part: "icon", class: "select__icon" }, index.h("six-icon", { size: "medium" }, "expand_more"))), index.h("six-input", { ref: (el) => (this.inputElement = el), class: {
404
469
  select__input: true,
405
470
  'select__hidden-select': !this.autocomplete,
406
471
  }, "aria-hidden": "true", required: this.required, onInvalid: this.handleInvalid, onFocus: this.handleFocus, clearable: this.clearable, placeholder: this.placeholder, pill: this.pill, disabled: this.disabled, size: this.size, tabIndex: -1 })), index.h("six-menu", { ref: (el) => (this.menu = el), part: "menu", class: {
407
472
  select__menu: true,
408
473
  'select__menu--filtered': this.filter || this.asyncFilter,
409
474
  'select__menu--hidden': !this.hasMenuItems(),
410
- }, "onSix-menu-item-selected": this.handleMenuSelect, items: this.options, virtualScroll: this.virtualScroll, "remove-box-shadow": true }, index.h("slot", { onSlotchange: this.handleSlotChange })))));
411
- }
412
- hasSelection() {
413
- if (this.multiple) {
414
- return Array.isArray(this.value) ? this.value.length > 0 : false;
415
- }
416
- return this.value !== '';
475
+ }, "onSix-menu-item-selected": (event) => this.toggleItem(event.detail.item), items: this.options, virtualScroll: this.virtualScroll, "remove-box-shadow": true }, index.h("slot", { onSlotchange: this.handleSlotChange })))));
417
476
  }
418
477
  get host() { return index.getElement(this); }
419
478
  static get watchers() { return {