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