@scania/tegel 1.23.0-value-prop.beta.1 → 1.23.0-value-prop.beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/dist/cjs/loader.cjs.js +1 -1
  2. package/dist/cjs/tds-checkbox.cjs.entry.js +2 -9
  3. package/dist/cjs/tds-dropdown_2.cjs.entry.js +62 -101
  4. package/dist/cjs/tds-slider.cjs.entry.js +7 -33
  5. package/dist/cjs/tegel.cjs.js +1 -1
  6. package/dist/collection/components/checkbox/checkbox.js +3 -19
  7. package/dist/collection/components/dropdown/dropdown.js +66 -103
  8. package/dist/collection/components/slider/slider.js +8 -34
  9. package/dist/components/{p-e7868876.js → p-462b77e8.js} +1 -1
  10. package/dist/components/{p-097af62b.js → p-4d8f8d5c.js} +63 -101
  11. package/dist/components/{p-d921fe75.js → p-e4d7c655.js} +3 -10
  12. package/dist/components/tds-checkbox.js +1 -1
  13. package/dist/components/tds-dropdown-option.js +1 -1
  14. package/dist/components/tds-dropdown.js +1 -1
  15. package/dist/components/tds-slider.js +7 -33
  16. package/dist/components/tds-table-body-row.js +1 -1
  17. package/dist/components/tds-table-footer.js +3 -3
  18. package/dist/components/tds-table-header.js +1 -1
  19. package/dist/esm/loader.js +1 -1
  20. package/dist/esm/tds-checkbox.entry.js +2 -9
  21. package/dist/esm/tds-dropdown_2.entry.js +62 -101
  22. package/dist/esm/tds-slider.entry.js +8 -34
  23. package/dist/esm/tegel.js +1 -1
  24. package/dist/tegel/p-0c05887d.entry.js +1 -0
  25. package/dist/tegel/p-a464920f.entry.js +1 -0
  26. package/dist/tegel/p-f91c6e9d.entry.js +1 -0
  27. package/dist/tegel/tegel.esm.js +1 -1
  28. package/dist/types/components/checkbox/checkbox.d.ts +0 -2
  29. package/dist/types/components/dropdown/dropdown.d.ts +8 -5
  30. package/dist/types/components/slider/slider.d.ts +0 -7
  31. package/package.json +1 -1
  32. package/dist/tegel/p-2557b79b.entry.js +0 -1
  33. package/dist/tegel/p-6a52ed63.entry.js +0 -1
  34. package/dist/tegel/p-a0925278.entry.js +0 -1
@@ -1,4 +1,4 @@
1
- import { h, } from "@stencil/core";
1
+ import { h } from "@stencil/core";
2
2
  import generateUniqueId from "../../utils/generateUniqueId";
3
3
  /**
4
4
  * @slot label - Slot for the label text.
@@ -43,19 +43,12 @@ export class TdsCheckbox {
43
43
  handleBlur(event) {
44
44
  this.tdsBlur.emit(event);
45
45
  }
46
- /** Listens for a reset event inside a form */
47
- handleFormReset(event) {
48
- if (this.host.closest('form') === event.target) {
49
- this.checked = false;
50
- this.indeterminate = false;
51
- }
52
- }
53
46
  render() {
54
- return (h("div", { key: '068b73081ab2b1b24d58fd2afd70f2b0e4308745', class: "tds-checkbox" }, h("input", { key: '97bd225b10dea56b8166ce3d5c2e4569a7dc76f9',
47
+ return (h("div", { key: '0efb982ab13c1d75681614675b649e010707b701', class: "tds-checkbox" }, h("input", { key: '834b29962978ea1cf7249018e6b7eea2417da5f4',
55
48
  // eslint-disable-next-line no-return-assign
56
49
  ref: (inputElement) => (this.inputElement = inputElement), indeterminate: this.indeterminate, "aria-checked": this.checked, "aria-required": this.required, "aria-describedby": this.host.getAttribute('aria-describedby'), "aria-labelledby": this.host.getAttribute('aria-labelledby'), required: this.required, type: "checkbox", name: this.name, value: this.value, id: this.checkboxId, checked: this.checked, disabled: this.disabled, onFocus: (event) => this.handleFocus(event), onBlur: (event) => this.handleBlur(event), onChange: () => {
57
50
  this.handleChange();
58
- } }), h("label", { key: '9cfe0411c9b26d12229de7fdb9421b333da0199c', htmlFor: this.checkboxId }, h("slot", { key: '17d2e45ddf05aa409926f3df82caab7a4f110b72', name: "label" }))));
51
+ } }), h("label", { key: '2150346b336440768beac655de035bf470f9e492', htmlFor: this.checkboxId }, h("slot", { key: 'df61654810e46b8707709d86bae7bdfd627724ee', name: "label" }))));
59
52
  }
60
53
  static get is() { return "tds-checkbox"; }
61
54
  static get encapsulation() { return "scoped"; }
@@ -283,13 +276,4 @@ export class TdsCheckbox {
283
276
  "methodName": "handleIndeterminateState"
284
277
  }];
285
278
  }
286
- static get listeners() {
287
- return [{
288
- "name": "reset",
289
- "method": "handleFormReset",
290
- "target": "document",
291
- "capture": false,
292
- "passive": false
293
- }];
294
- }
295
279
  }
@@ -7,39 +7,13 @@ import appendHiddenInput from "../../utils/appendHiddenInput";
7
7
  */
8
8
  export class TdsDropdown {
9
9
  constructor() {
10
- this.handleChange = () => {
11
- const value = Array.isArray(this.value) ? this.value.join(',') : this.value;
12
- this.tdsChange.emit({
13
- name: this.name,
14
- value: value !== null && value !== void 0 ? value : null,
15
- });
16
- };
17
10
  this.setDefaultOption = () => {
18
11
  if (this.defaultValue) {
19
- const children = Array.from(this.host.children).filter((element) => element.tagName === 'TDS-DROPDOWN-OPTION');
20
- if (children.length === 0) {
21
- console.warn('TDS DROPDOWN: No options found. Disregard if loading data asynchronously.');
22
- return;
23
- }
24
12
  const defaultValues = this.multiselect
25
13
  ? new Set(this.defaultValue.split(','))
26
14
  : [this.defaultValue];
27
- const childrenMap = new Map(children.map((element) => [element.value, element]));
28
- const matchedValues = Array.from(defaultValues).filter((value) => {
29
- const element = childrenMap.get(value);
30
- if (element) {
31
- element.setSelected(true);
32
- return true;
33
- }
34
- return false;
35
- });
36
- if (matchedValues.length > 0) {
37
- this.value = [...new Set(this.value ? [...this.value, ...matchedValues] : matchedValues)];
38
- this.setValueAttribute();
39
- }
40
- else {
41
- console.warn(`TDS DROPDOWN: No matching option found for defaultValue "${this.defaultValue}"`);
42
- }
15
+ const normalizedValues = Array.from(defaultValues);
16
+ this.updateDropdownState(normalizedValues);
43
17
  }
44
18
  };
45
19
  this.getChildren = () => {
@@ -152,12 +126,6 @@ export class TdsDropdown {
152
126
  this.handleBlur = (event) => {
153
127
  this.tdsBlur.emit(event);
154
128
  };
155
- this.resetInput = () => {
156
- const inputEl = this.host.querySelector('input');
157
- if (inputEl) {
158
- this.reset();
159
- }
160
- };
161
129
  this.name = undefined;
162
130
  this.disabled = false;
163
131
  this.helper = undefined;
@@ -174,70 +142,75 @@ export class TdsDropdown {
174
142
  this.normalizeText = true;
175
143
  this.noResultText = 'No result';
176
144
  this.defaultValue = undefined;
177
- this.value = undefined;
145
+ this.value = null;
178
146
  this.open = false;
179
147
  this.internalValue = undefined;
180
148
  this.filterResult = undefined;
181
149
  this.filterFocus = undefined;
150
+ this.selectedOptions = [];
182
151
  }
183
152
  handleValueChange(newValue) {
184
- // Convert both newValue and this.value to arrays for comparison
185
- const newValueArray = Array.isArray(newValue) ? newValue : newValue ? [newValue] : [];
186
- const currentValueArray = Array.isArray(this.value)
187
- ? this.value
188
- : this.value
189
- ? [this.value]
190
- : [];
191
- // Check if the new value is different from the current value
192
- const hasChanged = newValueArray.length !== currentValueArray.length ||
193
- newValueArray.some((val, index) => val !== currentValueArray[index]);
194
- if (hasChanged) {
195
- // Proceed with updating selections and emitting changes
196
- this.updateSelections(newValueArray);
197
- this.handleChange();
153
+ // Normalize to array
154
+ const normalizedValue = this.normalizeValue(newValue);
155
+ // Only update if actually changed
156
+ if (this.hasValueChanged(normalizedValue, this.selectedOptions)) {
157
+ this.updateDropdownState(normalizedValue);
198
158
  }
199
159
  }
200
- updateSelections(valueArray) {
201
- // Reset current selections
202
- this.getChildren().forEach((element) => {
203
- element.setSelected(false);
204
- });
205
- if (valueArray) {
206
- // Validate and filter values
207
- const validValues = valueArray.filter((val) => {
208
- const optionExists = this.getChildren().some((element) => element.value === val);
209
- if (!optionExists) {
210
- console.warn(`Option with value "${val}" does not exist`);
211
- }
212
- return optionExists;
213
- });
214
- // Update internal state and selections
215
- this.internalValue = validValues.join(', ');
216
- this.getChildren().forEach((element) => {
217
- if (validValues.includes(element.value)) {
218
- element.setSelected(true);
219
- }
220
- });
221
- // Update value prop with validated values
222
- if (this.multiselect) {
223
- this.value = validValues;
224
- }
225
- else {
226
- this.value = validValues[0] || null;
160
+ normalizeValue(value) {
161
+ if (!value)
162
+ return [];
163
+ return Array.isArray(value) ? value : [value];
164
+ }
165
+ hasValueChanged(newValue, currentValue) {
166
+ if (newValue.length !== currentValue.length)
167
+ return true;
168
+ return newValue.some((val) => !currentValue.includes(val));
169
+ }
170
+ updateDropdownState(values) {
171
+ // Update internal state
172
+ this.selectedOptions = this.validateValues(values);
173
+ // Update DOM
174
+ this.updateOptionElements();
175
+ // Update display value
176
+ this.updateDisplayValue();
177
+ // Emit change event
178
+ this.emitChange();
179
+ // Update value attribute
180
+ this.setValueAttribute();
181
+ }
182
+ validateValues(values) {
183
+ return values.filter((val) => {
184
+ var _a;
185
+ const isValid = (_a = this.getChildren()) === null || _a === void 0 ? void 0 : _a.some((element) => element.value === val);
186
+ if (!isValid) {
187
+ console.warn(`Option with value "${val}" does not exist`);
227
188
  }
228
- }
229
- else {
230
- // Handle null/undefined case
231
- this.internalValue = '';
232
- this.value = this.multiselect ? [] : null;
233
- }
234
- // Emit change events
235
- this.handleChange();
236
- // Update filter input if present
189
+ return isValid;
190
+ });
191
+ }
192
+ updateOptionElements() {
193
+ var _a;
194
+ (_a = this.getChildren()) === null || _a === void 0 ? void 0 : _a.forEach((element) => {
195
+ element.setSelected(this.selectedOptions.includes(element.value));
196
+ });
197
+ }
198
+ updateDisplayValue() {
199
+ this.internalValue = this.getSelectedChildrenLabels().join(', ');
237
200
  if (this.filter && this.inputElement) {
238
201
  this.inputElement.value = this.internalValue;
239
202
  }
240
- this.setValueAttribute();
203
+ }
204
+ emitChange() {
205
+ // Update the value prop to match validated state
206
+ this.value = this.multiselect ? this.selectedOptions : this.selectedOptions[0] || null;
207
+ const value = this.multiselect
208
+ ? this.selectedOptions.join(',')
209
+ : this.selectedOptions[0] || null;
210
+ this.tdsChange.emit({
211
+ name: this.name,
212
+ value: value !== null && value !== void 0 ? value : null,
213
+ });
241
214
  }
242
215
  async setValue(value) {
243
216
  this.value = value;
@@ -335,23 +308,11 @@ export class TdsDropdown {
335
308
  this.value = value;
336
309
  }
337
310
  }
338
- componentDidRender() {
339
- const form = this.host.closest('form');
340
- if (form) {
341
- form.addEventListener('reset', this.resetInput);
342
- }
343
- }
344
- disconnectedCallback() {
345
- const form = this.host.closest('form');
346
- if (form) {
347
- form.removeEventListener('reset', this.resetInput);
348
- }
349
- }
350
311
  render() {
351
312
  var _a, _b, _c;
352
313
  const valueArray = Array.isArray(this.value) ? this.value : this.value ? [this.value] : [];
353
314
  appendHiddenInput(this.host, this.name, valueArray.map((value) => value).toString(), this.disabled);
354
- return (h(Host, { key: '65dc50a4788d2fdade55db41bfc6cdfcad76b7d5', role: "select", class: `${this.modeVariant ? `tds-mode-variant-${this.modeVariant}` : ''}` }, this.label && this.labelPosition === 'outside' && (h("div", { key: '389e82159e7756782fc12af15d7efb43d8cfeafb', class: `label-outside ${this.disabled ? 'disabled' : ''}` }, this.label)), h("div", { key: 'e7e4585e630ebbab3ae178bbe7b0d3eb0793ba60', class: `dropdown-select ${this.size} ${this.disabled ? 'disabled' : ''}` }, this.filter ? (h("div", { class: {
315
+ return (h(Host, { key: 'c3a3742ba6f875aee1b9e7abb4ab2c2b2331d3fc', role: "select", class: `${this.modeVariant ? `tds-mode-variant-${this.modeVariant}` : ''}` }, this.label && this.labelPosition === 'outside' && (h("div", { key: '0b45d4e910577e1cfd350f6f60e544839f905865', class: `label-outside ${this.disabled ? 'disabled' : ''}` }, this.label)), h("div", { key: '3557975c254df99c9f97dac71a6d9e66268c09f2', class: `dropdown-select ${this.size} ${this.disabled ? 'disabled' : ''}` }, this.filter ? (h("div", { class: {
355
316
  filter: true,
356
317
  focus: this.filterFocus,
357
318
  disabled: this.disabled,
@@ -393,7 +354,7 @@ export class TdsDropdown {
393
354
  label-inside-as-placeholder
394
355
  ${this.size}
395
356
  ${((_b = this.value) === null || _b === void 0 ? void 0 : _b.length) ? 'selected' : ''}
396
- ` }, this.label)), h("div", { class: `placeholder ${this.size}` }, ((_c = this.value) === null || _c === void 0 ? void 0 : _c.length) ? this.getValue() : this.placeholder), h("tds-icon", { "aria-label": "Open/Close dropdown", svgTitle: "Open/Close dropdown", class: `menu-icon ${this.open ? 'open' : 'closed'}`, name: "chevron_down", size: "16px" }))))), h("div", { key: 'c79561725649f2cda46d13e7290ec0ea698f930e', ref: (element) => (this.dropdownList = element), class: {
357
+ ` }, this.label)), h("div", { class: `placeholder ${this.size}` }, ((_c = this.value) === null || _c === void 0 ? void 0 : _c.length) ? this.getValue() : this.placeholder), h("tds-icon", { "aria-label": "Open/Close dropdown", svgTitle: "Open/Close dropdown", class: `menu-icon ${this.open ? 'open' : 'closed'}`, name: "chevron_down", size: "16px" }))))), h("div", { key: 'bf74f7277ac93324469c9f371a1a41598366d833', ref: (element) => (this.dropdownList = element), class: {
397
358
  'dropdown-list': true,
398
359
  [this.size]: true,
399
360
  [this.getOpenDirection()]: true,
@@ -402,7 +363,7 @@ export class TdsDropdown {
402
363
  'closed': !this.open,
403
364
  [`animation-enter-${this.animation}`]: this.animation !== 'none' && this.open,
404
365
  [`animation-exit-${this.animation}`]: this.animation !== 'none' && !this.open,
405
- } }, h("slot", { key: '958aa0e620a825c8d20ec4cfeae334c3c59e85dc', onSlotchange: () => this.handleSlotChange() }), this.filterResult === 0 && this.noResultText !== '' && (h("div", { key: '8138e3340cd62d46ea8938b2d9f0609c03951a1f', class: `no-result ${this.size}` }, this.noResultText))), this.helper && (h("div", { key: '3e7a1e9e8520eadc5b805d5512c6fbe177d69755', class: `helper ${this.error ? 'error' : ''} ${this.disabled ? 'disabled' : ''}` }, this.error && h("tds-icon", { key: '882c2152620d7d7c2ad576db12ecd65d04446600', name: "error", size: "16px" }), this.helper))));
366
+ } }, h("slot", { key: '0bbfde317a9c9f757236f9a3aa45bc7549cba134', onSlotchange: () => this.handleSlotChange() }), this.filterResult === 0 && this.noResultText !== '' && (h("div", { key: '4a2d556e26c1aedc6aad4ec1031e5290d4d6e28a', class: `no-result ${this.size}` }, this.noResultText))), this.helper && (h("div", { key: '506b816ed70834aef3fd3e22acc19567761d2645', class: `helper ${this.error ? 'error' : ''} ${this.disabled ? 'disabled' : ''}` }, this.error && h("tds-icon", { key: 'f890f8df6431d6a437459a245711731091cbe4ad', name: "error", size: "16px" }), this.helper))));
406
367
  }
407
368
  static get is() { return "tds-dropdown"; }
408
369
  static get encapsulation() { return "shadow"; }
@@ -715,7 +676,8 @@ export class TdsDropdown {
715
676
  "text": "Value of the dropdown. For multiselect, provide array of strings. For single select, provide a string."
716
677
  },
717
678
  "attribute": "value",
718
- "reflect": false
679
+ "reflect": false,
680
+ "defaultValue": "null"
719
681
  }
720
682
  };
721
683
  }
@@ -724,7 +686,8 @@ export class TdsDropdown {
724
686
  "open": {},
725
687
  "internalValue": {},
726
688
  "filterResult": {},
727
- "filterFocus": {}
689
+ "filterFocus": {},
690
+ "selectedOptions": {}
728
691
  };
729
692
  }
730
693
  static get events() {
@@ -1,4 +1,4 @@
1
- import { h, } from "@stencil/core";
1
+ import { h } from "@stencil/core";
2
2
  import generateUniqueId from "../../utils/generateUniqueId";
3
3
  export class TdsSlider {
4
4
  constructor() {
@@ -16,11 +16,6 @@ export class TdsSlider {
16
16
  this.useSnapping = false;
17
17
  this.supposedValueSlot = -1;
18
18
  this.resizeObserverAdded = false;
19
- this.resetEventListenerAdded = false;
20
- this.resetToInitialValue = () => {
21
- this.forceValueUpdate(this.initialValue);
22
- this.reset();
23
- };
24
19
  this.label = '';
25
20
  this.value = '0';
26
21
  this.min = '0';
@@ -300,46 +295,26 @@ export class TdsSlider {
300
295
  }
301
296
  this.calculateThumbLeftFromValue(this.value);
302
297
  this.updateTrack();
303
- // Only set the initial value once:
304
- if (!this.initialValue) {
305
- this.initialValue = this.value;
306
- }
307
- }
308
- componentDidRender() {
309
- // Only add the event listener once:
310
- if (!this.resetEventListenerAdded) {
311
- this.formElement = this.host.closest('form');
312
- if (this.formElement) {
313
- this.formElement.addEventListener('reset', this.resetToInitialValue);
314
- this.resetEventListenerAdded = true;
315
- }
316
- }
317
- }
318
- disconnectedCallback() {
319
- if (this.resetEventListenerAdded && this.formElement) {
320
- this.formElement.removeEventListener('reset', this.resetToInitialValue);
321
- this.resetEventListenerAdded = false;
322
- }
323
298
  }
324
299
  render() {
325
- return (h("div", { key: 'ed4c71d1701e0711d8b01c015f137f6a3f10457e', class: {
300
+ return (h("div", { key: 'fd7d051192c33b19e8c68cbeaa50ea43149457bb', class: {
326
301
  'tds-slider-wrapper': true,
327
302
  'read-only': this.readOnly,
328
- } }, h("input", { key: '7d85ba109ec41e45a4ced646cfe092832b2013a7', class: "tds-slider-native-element", type: "range", name: this.name, min: this.min, max: this.max, value: this.value, disabled: this.disabled }), h("div", { key: '7c32efe653a6437068026e0b612bd1cdb0fd580d', class: {
303
+ } }, h("input", { key: 'd2fe02893f865f5791736cb5f05b5bcd2494e471', class: "tds-slider-native-element", type: "range", name: this.name, min: this.min, max: this.max, value: this.value, disabled: this.disabled }), h("div", { key: '2d436a5654cb20923cd20ed61f9449bd0705edd2', class: {
329
304
  'tds-slider': true,
330
305
  'disabled': this.disabled,
331
306
  'tds-slider-small': this.useSmall,
332
307
  }, ref: (el) => {
333
308
  this.wrapperElement = el;
334
- } }, h("label", { key: '5561410214fda42ddb4553084f312de9943f825b', class: this.showTickNumbers && 'offset' }, this.label), this.useInput && (h("div", { key: '37340de05febbca285f031bd8df7d9c2588e315d', class: "tds-slider__input-values" }, h("div", { key: 'e973831529eb93eb0b0da6c5f92bd838dfb9bcdb', class: "tds-slider__input-value min-value" }, this.min))), this.useControls && (h("div", { key: '1a710d2d1ffac7533f9bae2908d4341d3b40e2f0', class: "tds-slider__controls" }, h("div", { key: '0a741834782d8e69a7d55e6cd87a3fdf4938d744', class: "tds-slider__control tds-slider__control-minus", onClick: (event) => this.stepLeft(event) }, h("tds-icon", { key: '8c67943ac2e15d742726e76c2b4c029d15c20f32', name: "minus", size: "16px" })))), h("div", { key: '96c4229007fbe882e106bcc3deb34f504c9604e3', class: "tds-slider-inner" }, this.tickValues.length > 0 && (h("div", { key: '905fc1a02070f5419f76ec5d60d8f55d89d4650b', class: "tds-slider__value-dividers-wrapper" }, h("div", { key: 'd2ccbea1b6e26ab1855c81e71730bebea0da37d8', class: "tds-slider__value-dividers" }, this.tickValues.map((value) => (h("div", { class: "tds-slider__value-divider" }, this.showTickNumbers && h("span", null, value))))))), h("div", { key: '30c9b4bb6f59631d443345ee6d1edf1973a83d0b', class: "tds-slider__track", ref: (el) => {
309
+ } }, h("label", { key: 'd9d444d15acabbbc23c7b7633e5312f405ff9120', class: this.showTickNumbers && 'offset' }, this.label), this.useInput && (h("div", { key: '2f0d0419138851724891e2ab04fef2f3b3e099f1', class: "tds-slider__input-values" }, h("div", { key: '7f23007c0f4a1aa6358ffa7c5aaae027d0927b63', class: "tds-slider__input-value min-value" }, this.min))), this.useControls && (h("div", { key: 'df4a00a40c541b83aa8459dfcdaf22c348e2c80a', class: "tds-slider__controls" }, h("div", { key: '96cc419d369098137895b725f97a8fa3d7d50dfc', class: "tds-slider__control tds-slider__control-minus", onClick: (event) => this.stepLeft(event) }, h("tds-icon", { key: '09ed43c9f2fe81baeada6a07e4cba18027f04ba1', name: "minus", size: "16px" })))), h("div", { key: '402647683b57076bd4ac3ce3d754585a89a48e08', class: "tds-slider-inner" }, this.tickValues.length > 0 && (h("div", { key: 'd80c648eca47c7e52725e967a32fe4a4692a5729', class: "tds-slider__value-dividers-wrapper" }, h("div", { key: '030106df49f12a55c1b32a9c1c257f449629644a', class: "tds-slider__value-dividers" }, this.tickValues.map((value) => (h("div", { class: "tds-slider__value-divider" }, this.showTickNumbers && h("span", null, value))))))), h("div", { key: 'fef7013f82a191c32bc3a4d297f5e10a4db127a1', class: "tds-slider__track", ref: (el) => {
335
310
  this.trackElement = el;
336
- }, tabindex: this.disabled ? '-1' : '0' }, h("div", { key: '7acbccae98c481c4cfaeb2dc66d67a2e19575b93', class: "tds-slider__track-fill", ref: (el) => {
311
+ }, tabindex: this.disabled ? '-1' : '0' }, h("div", { key: '24a583182c45114d1e011bffef0f81f1e4f93a36', class: "tds-slider__track-fill", ref: (el) => {
337
312
  this.trackFillElement = el;
338
- } }), h("div", { key: '46a5c3135c5f765d5fb0845372dc3854586fa44d', class: "tds-slider__thumb", ref: (el) => {
313
+ } }), h("div", { key: '3bea53237beb92f41264386fb5ac181d1e9966a4', class: "tds-slider__thumb", ref: (el) => {
339
314
  this.thumbElement = el;
340
- }, onMouseDown: () => this.grabThumb(), onTouchStart: () => this.grabThumb() }, this.tooltip && (h("div", { key: 'd39cd29d1e6302f8bd4a3d827797f8822e24b84d', class: "tds-slider__value" }, this.value, h("svg", { key: '5946f90b70b2afb2efc7f3a3bc5817a82ac3ca4a', width: "18", height: "14", viewBox: "0 0 18 14", fill: "none", xmlns: "http://www.w3.org/2000/svg" }, h("path", { key: '9456df642aca39b94b17bb529ca02e2d6a2fde6c', d: "M8.15882 12.6915L0.990487 1.54076C0.562658 0.875246 1.0405 0 1.83167 0H16.1683C16.9595 0 17.4373 0.875246 17.0095 1.54076L9.84118 12.6915C9.44754 13.3038 8.55246 13.3038 8.15882 12.6915Z", fill: "currentColor" })))), h("div", { key: 'b4ca73a085f837d7e87e3334b8e58e5638125118', class: "tds-slider__thumb-inner", ref: (el) => {
315
+ }, onMouseDown: () => this.grabThumb(), onTouchStart: () => this.grabThumb() }, this.tooltip && (h("div", { key: '3ac44629cad3b03524602f9babe7fa4582b38660', class: "tds-slider__value" }, this.value, h("svg", { key: '5adbbcc274555d14454c5329f0eea8c072a3db2c', width: "18", height: "14", viewBox: "0 0 18 14", fill: "none", xmlns: "http://www.w3.org/2000/svg" }, h("path", { key: '248b1f8521b89be4214631e411c0ba9c7bcc07a8', d: "M8.15882 12.6915L0.990487 1.54076C0.562658 0.875246 1.0405 0 1.83167 0H16.1683C16.9595 0 17.4373 0.875246 17.0095 1.54076L9.84118 12.6915C9.44754 13.3038 8.55246 13.3038 8.15882 12.6915Z", fill: "currentColor" })))), h("div", { key: 'bc778a9ccd25a5229aa7685cc6c22ed5385b9d98', class: "tds-slider__thumb-inner", ref: (el) => {
341
316
  this.thumbInnerElement = el;
342
- } })))), this.useInput && (h("div", { key: '6574286ac7764807fd1e18875d6fa39ab7f7b304', class: "tds-slider__input-values" }, h("div", { key: '57a92adf59551f551c4ae06355c276a69b34028a', class: "tds-slider__input-value", onClick: (event) => this.stepLeft(event) }, this.max), h("div", { key: '0e1632ca8c9510177d349147749e3162aa46f219', class: "tds-slider__input-field-wrapper" }, h("input", { key: '094d194bce54d1073a5d657f7bc3f30107f5fe41', size: this.calculateInputSizeFromMax(), class: "tds-slider__input-field", value: this.value, readOnly: this.readOnly, onBlur: (event) => this.updateSliderValueOnInputChange(event), onKeyDown: (event) => this.handleInputFieldEnterPress(event), type: "number", min: this.min, max: this.max })))), this.useControls && (h("div", { key: '207398a3fd02e11f09c70ebbb8b293d6c16afd1f', class: "tds-slider__controls" }, h("div", { key: 'ca93ce9a55d0db25a3eaefd6e4dbc53106afc895', class: "tds-slider__control tds-slider__control-plus", onClick: (event) => this.stepRight(event) }, h("tds-icon", { key: '6ab123f8701fdd93580a61c500ae6da658b547fd', name: "plus", size: "16px" })))))));
317
+ } })))), this.useInput && (h("div", { key: '077ffffeb0986504a2c9fc4e1b08095ec689402c', class: "tds-slider__input-values" }, h("div", { key: '74a528a286e2b49a6739c5817cca8a0436b908b9', class: "tds-slider__input-value", onClick: (event) => this.stepLeft(event) }, this.max), h("div", { key: 'af2a647636c8eecba19637aa92ddda37adc52a1b', class: "tds-slider__input-field-wrapper" }, h("input", { key: '02701d15de6119994f7be13b9c9ac69ae6f2269b', size: this.calculateInputSizeFromMax(), class: "tds-slider__input-field", value: this.value, readOnly: this.readOnly, onBlur: (event) => this.updateSliderValueOnInputChange(event), onKeyDown: (event) => this.handleInputFieldEnterPress(event), type: "number", min: this.min, max: this.max })))), this.useControls && (h("div", { key: 'ef215ef613c381601674d4bb7dbea583a3ddde2a', class: "tds-slider__controls" }, h("div", { key: '4e553194348daf32529c9c8cedc32b0686ac32ff', class: "tds-slider__control tds-slider__control-plus", onClick: (event) => this.stepRight(event) }, h("tds-icon", { key: 'd5d67ea7ff64ed19d28bd078acad56ebda742f93', name: "plus", size: "16px" })))))));
343
318
  }
344
319
  static get is() { return "tds-slider"; }
345
320
  static get originalStyleUrls() {
@@ -698,7 +673,6 @@ export class TdsSlider {
698
673
  }
699
674
  };
700
675
  }
701
- static get elementRef() { return "host"; }
702
676
  static get watchers() {
703
677
  return [{
704
678
  "propName": "value",
@@ -1,5 +1,5 @@
1
1
  import { p as proxyCustomElement, H, d as createEvent, h, c as Host } from './p-28ef5186.js';
2
- import { d as defineCustomElement$2 } from './p-d921fe75.js';
2
+ import { d as defineCustomElement$2 } from './p-e4d7c655.js';
3
3
  import { d as defineCustomElement$1 } from './p-18c1245b.js';
4
4
 
5
5
  const dropdownOptionCss = ":host{box-sizing:border-box;display:block;background-color:var(--tds-dropdown-option-background)}:host *{box-sizing:border-box}:host .dropdown-option{color:var(--tds-dropdown-option-color);border-bottom:1px solid var(--tds-dropdown-option-border);font:var(--tds-detail-02);letter-spacing:var(--tds-detail-02-ls);overflow-wrap:anywhere;transition:background-color var(--tds-motion-duration-fast-02) var(--tds-motion-easing-scania)}:host .dropdown-option.selected{background-color:var(--tds-dropdown-option-background-selected)}:host .dropdown-option.disabled{color:var(--tds-dropdown-option-color-disabled)}:host .dropdown-option button:focus{outline:2px solid var(--tds-blue-400);outline-offset:-2px}:host .dropdown-option button{all:unset;width:100%}:host .dropdown-option button.lg{padding:19px 0 20px}:host .dropdown-option button.md{padding:15px 0 16px}:host .dropdown-option button.sm{padding:11px 0 12px}:host .dropdown-option button.xs{padding:7px 0 8px}:host .dropdown-option button .single-select{display:flex;align-items:center;justify-content:space-between;padding:0 16px}:host .dropdown-option .multiselect{width:100%;height:100%}:host .dropdown-option .multiselect tds-checkbox{display:flex;height:100%;width:100%}:host .dropdown-option .multiselect tds-checkbox.lg{padding:15px 16px 16px}:host .dropdown-option .multiselect tds-checkbox.md{padding:11px 16px 12px}:host .dropdown-option .multiselect tds-checkbox.sm{padding:7px 16px 8px}:host .dropdown-option .multiselect tds-checkbox.xs{padding:7px 16px 8px}:host .dropdown-option:hover{background-color:var(--tds-dropdown-option-background-hover);cursor:pointer}:host .dropdown-option:hover.disabled{background-color:var(--tds-dropdown-option-background);cursor:not-allowed}:host([hidden]){display:none}";
@@ -72,39 +72,13 @@ const TdsDropdown = /*@__PURE__*/ proxyCustomElement(class TdsDropdown extends H
72
72
  this.tdsBlur = createEvent(this, "tdsBlur", 6);
73
73
  this.tdsInput = createEvent(this, "tdsInput", 6);
74
74
  this.tdsValueChange = createEvent(this, "tdsValueChange", 6);
75
- this.handleChange = () => {
76
- const value = Array.isArray(this.value) ? this.value.join(',') : this.value;
77
- this.tdsChange.emit({
78
- name: this.name,
79
- value: value !== null && value !== void 0 ? value : null,
80
- });
81
- };
82
75
  this.setDefaultOption = () => {
83
76
  if (this.defaultValue) {
84
- const children = Array.from(this.host.children).filter((element) => element.tagName === 'TDS-DROPDOWN-OPTION');
85
- if (children.length === 0) {
86
- console.warn('TDS DROPDOWN: No options found. Disregard if loading data asynchronously.');
87
- return;
88
- }
89
77
  const defaultValues = this.multiselect
90
78
  ? new Set(this.defaultValue.split(','))
91
79
  : [this.defaultValue];
92
- const childrenMap = new Map(children.map((element) => [element.value, element]));
93
- const matchedValues = Array.from(defaultValues).filter((value) => {
94
- const element = childrenMap.get(value);
95
- if (element) {
96
- element.setSelected(true);
97
- return true;
98
- }
99
- return false;
100
- });
101
- if (matchedValues.length > 0) {
102
- this.value = [...new Set(this.value ? [...this.value, ...matchedValues] : matchedValues)];
103
- this.setValueAttribute();
104
- }
105
- else {
106
- console.warn(`TDS DROPDOWN: No matching option found for defaultValue "${this.defaultValue}"`);
107
- }
80
+ const normalizedValues = Array.from(defaultValues);
81
+ this.updateDropdownState(normalizedValues);
108
82
  }
109
83
  };
110
84
  this.getChildren = () => {
@@ -217,12 +191,6 @@ const TdsDropdown = /*@__PURE__*/ proxyCustomElement(class TdsDropdown extends H
217
191
  this.handleBlur = (event) => {
218
192
  this.tdsBlur.emit(event);
219
193
  };
220
- this.resetInput = () => {
221
- const inputEl = this.host.querySelector('input');
222
- if (inputEl) {
223
- this.reset();
224
- }
225
- };
226
194
  this.name = undefined;
227
195
  this.disabled = false;
228
196
  this.helper = undefined;
@@ -239,70 +207,75 @@ const TdsDropdown = /*@__PURE__*/ proxyCustomElement(class TdsDropdown extends H
239
207
  this.normalizeText = true;
240
208
  this.noResultText = 'No result';
241
209
  this.defaultValue = undefined;
242
- this.value = undefined;
210
+ this.value = null;
243
211
  this.open = false;
244
212
  this.internalValue = undefined;
245
213
  this.filterResult = undefined;
246
214
  this.filterFocus = undefined;
215
+ this.selectedOptions = [];
247
216
  }
248
217
  handleValueChange(newValue) {
249
- // Convert both newValue and this.value to arrays for comparison
250
- const newValueArray = Array.isArray(newValue) ? newValue : newValue ? [newValue] : [];
251
- const currentValueArray = Array.isArray(this.value)
252
- ? this.value
253
- : this.value
254
- ? [this.value]
255
- : [];
256
- // Check if the new value is different from the current value
257
- const hasChanged = newValueArray.length !== currentValueArray.length ||
258
- newValueArray.some((val, index) => val !== currentValueArray[index]);
259
- if (hasChanged) {
260
- // Proceed with updating selections and emitting changes
261
- this.updateSelections(newValueArray);
262
- this.handleChange();
218
+ // Normalize to array
219
+ const normalizedValue = this.normalizeValue(newValue);
220
+ // Only update if actually changed
221
+ if (this.hasValueChanged(normalizedValue, this.selectedOptions)) {
222
+ this.updateDropdownState(normalizedValue);
263
223
  }
264
224
  }
265
- updateSelections(valueArray) {
266
- // Reset current selections
267
- this.getChildren().forEach((element) => {
268
- element.setSelected(false);
269
- });
270
- if (valueArray) {
271
- // Validate and filter values
272
- const validValues = valueArray.filter((val) => {
273
- const optionExists = this.getChildren().some((element) => element.value === val);
274
- if (!optionExists) {
275
- console.warn(`Option with value "${val}" does not exist`);
276
- }
277
- return optionExists;
278
- });
279
- // Update internal state and selections
280
- this.internalValue = validValues.join(', ');
281
- this.getChildren().forEach((element) => {
282
- if (validValues.includes(element.value)) {
283
- element.setSelected(true);
284
- }
285
- });
286
- // Update value prop with validated values
287
- if (this.multiselect) {
288
- this.value = validValues;
289
- }
290
- else {
291
- this.value = validValues[0] || null;
225
+ normalizeValue(value) {
226
+ if (!value)
227
+ return [];
228
+ return Array.isArray(value) ? value : [value];
229
+ }
230
+ hasValueChanged(newValue, currentValue) {
231
+ if (newValue.length !== currentValue.length)
232
+ return true;
233
+ return newValue.some((val) => !currentValue.includes(val));
234
+ }
235
+ updateDropdownState(values) {
236
+ // Update internal state
237
+ this.selectedOptions = this.validateValues(values);
238
+ // Update DOM
239
+ this.updateOptionElements();
240
+ // Update display value
241
+ this.updateDisplayValue();
242
+ // Emit change event
243
+ this.emitChange();
244
+ // Update value attribute
245
+ this.setValueAttribute();
246
+ }
247
+ validateValues(values) {
248
+ return values.filter((val) => {
249
+ var _a;
250
+ const isValid = (_a = this.getChildren()) === null || _a === void 0 ? void 0 : _a.some((element) => element.value === val);
251
+ if (!isValid) {
252
+ console.warn(`Option with value "${val}" does not exist`);
292
253
  }
293
- }
294
- else {
295
- // Handle null/undefined case
296
- this.internalValue = '';
297
- this.value = this.multiselect ? [] : null;
298
- }
299
- // Emit change events
300
- this.handleChange();
301
- // Update filter input if present
254
+ return isValid;
255
+ });
256
+ }
257
+ updateOptionElements() {
258
+ var _a;
259
+ (_a = this.getChildren()) === null || _a === void 0 ? void 0 : _a.forEach((element) => {
260
+ element.setSelected(this.selectedOptions.includes(element.value));
261
+ });
262
+ }
263
+ updateDisplayValue() {
264
+ this.internalValue = this.getSelectedChildrenLabels().join(', ');
302
265
  if (this.filter && this.inputElement) {
303
266
  this.inputElement.value = this.internalValue;
304
267
  }
305
- this.setValueAttribute();
268
+ }
269
+ emitChange() {
270
+ // Update the value prop to match validated state
271
+ this.value = this.multiselect ? this.selectedOptions : this.selectedOptions[0] || null;
272
+ const value = this.multiselect
273
+ ? this.selectedOptions.join(',')
274
+ : this.selectedOptions[0] || null;
275
+ this.tdsChange.emit({
276
+ name: this.name,
277
+ value: value !== null && value !== void 0 ? value : null,
278
+ });
306
279
  }
307
280
  async setValue(value) {
308
281
  this.value = value;
@@ -400,23 +373,11 @@ const TdsDropdown = /*@__PURE__*/ proxyCustomElement(class TdsDropdown extends H
400
373
  this.value = value;
401
374
  }
402
375
  }
403
- componentDidRender() {
404
- const form = this.host.closest('form');
405
- if (form) {
406
- form.addEventListener('reset', this.resetInput);
407
- }
408
- }
409
- disconnectedCallback() {
410
- const form = this.host.closest('form');
411
- if (form) {
412
- form.removeEventListener('reset', this.resetInput);
413
- }
414
- }
415
376
  render() {
416
377
  var _a, _b, _c;
417
378
  const valueArray = Array.isArray(this.value) ? this.value : this.value ? [this.value] : [];
418
379
  appendHiddenInput(this.host, this.name, valueArray.map((value) => value).toString(), this.disabled);
419
- return (h(Host, { key: '65dc50a4788d2fdade55db41bfc6cdfcad76b7d5', role: "select", class: `${this.modeVariant ? `tds-mode-variant-${this.modeVariant}` : ''}` }, this.label && this.labelPosition === 'outside' && (h("div", { key: '389e82159e7756782fc12af15d7efb43d8cfeafb', class: `label-outside ${this.disabled ? 'disabled' : ''}` }, this.label)), h("div", { key: 'e7e4585e630ebbab3ae178bbe7b0d3eb0793ba60', class: `dropdown-select ${this.size} ${this.disabled ? 'disabled' : ''}` }, this.filter ? (h("div", { class: {
380
+ return (h(Host, { key: 'c3a3742ba6f875aee1b9e7abb4ab2c2b2331d3fc', role: "select", class: `${this.modeVariant ? `tds-mode-variant-${this.modeVariant}` : ''}` }, this.label && this.labelPosition === 'outside' && (h("div", { key: '0b45d4e910577e1cfd350f6f60e544839f905865', class: `label-outside ${this.disabled ? 'disabled' : ''}` }, this.label)), h("div", { key: '3557975c254df99c9f97dac71a6d9e66268c09f2', class: `dropdown-select ${this.size} ${this.disabled ? 'disabled' : ''}` }, this.filter ? (h("div", { class: {
420
381
  filter: true,
421
382
  focus: this.filterFocus,
422
383
  disabled: this.disabled,
@@ -458,7 +419,7 @@ const TdsDropdown = /*@__PURE__*/ proxyCustomElement(class TdsDropdown extends H
458
419
  label-inside-as-placeholder
459
420
  ${this.size}
460
421
  ${((_b = this.value) === null || _b === void 0 ? void 0 : _b.length) ? 'selected' : ''}
461
- ` }, this.label)), h("div", { class: `placeholder ${this.size}` }, ((_c = this.value) === null || _c === void 0 ? void 0 : _c.length) ? this.getValue() : this.placeholder), h("tds-icon", { "aria-label": "Open/Close dropdown", svgTitle: "Open/Close dropdown", class: `menu-icon ${this.open ? 'open' : 'closed'}`, name: "chevron_down", size: "16px" }))))), h("div", { key: 'c79561725649f2cda46d13e7290ec0ea698f930e', ref: (element) => (this.dropdownList = element), class: {
422
+ ` }, this.label)), h("div", { class: `placeholder ${this.size}` }, ((_c = this.value) === null || _c === void 0 ? void 0 : _c.length) ? this.getValue() : this.placeholder), h("tds-icon", { "aria-label": "Open/Close dropdown", svgTitle: "Open/Close dropdown", class: `menu-icon ${this.open ? 'open' : 'closed'}`, name: "chevron_down", size: "16px" }))))), h("div", { key: 'bf74f7277ac93324469c9f371a1a41598366d833', ref: (element) => (this.dropdownList = element), class: {
462
423
  'dropdown-list': true,
463
424
  [this.size]: true,
464
425
  [this.getOpenDirection()]: true,
@@ -467,7 +428,7 @@ const TdsDropdown = /*@__PURE__*/ proxyCustomElement(class TdsDropdown extends H
467
428
  'closed': !this.open,
468
429
  [`animation-enter-${this.animation}`]: this.animation !== 'none' && this.open,
469
430
  [`animation-exit-${this.animation}`]: this.animation !== 'none' && !this.open,
470
- } }, h("slot", { key: '958aa0e620a825c8d20ec4cfeae334c3c59e85dc', onSlotchange: () => this.handleSlotChange() }), this.filterResult === 0 && this.noResultText !== '' && (h("div", { key: '8138e3340cd62d46ea8938b2d9f0609c03951a1f', class: `no-result ${this.size}` }, this.noResultText))), this.helper && (h("div", { key: '3e7a1e9e8520eadc5b805d5512c6fbe177d69755', class: `helper ${this.error ? 'error' : ''} ${this.disabled ? 'disabled' : ''}` }, this.error && h("tds-icon", { key: '882c2152620d7d7c2ad576db12ecd65d04446600', name: "error", size: "16px" }), this.helper))));
431
+ } }, h("slot", { key: '0bbfde317a9c9f757236f9a3aa45bc7549cba134', onSlotchange: () => this.handleSlotChange() }), this.filterResult === 0 && this.noResultText !== '' && (h("div", { key: '4a2d556e26c1aedc6aad4ec1031e5290d4d6e28a', class: `no-result ${this.size}` }, this.noResultText))), this.helper && (h("div", { key: '506b816ed70834aef3fd3e22acc19567761d2645', class: `helper ${this.error ? 'error' : ''} ${this.disabled ? 'disabled' : ''}` }, this.error && h("tds-icon", { key: 'f890f8df6431d6a437459a245711731091cbe4ad', name: "error", size: "16px" }), this.helper))));
471
432
  }
472
433
  get host() { return this; }
473
434
  static get watchers() { return {
@@ -497,6 +458,7 @@ const TdsDropdown = /*@__PURE__*/ proxyCustomElement(class TdsDropdown extends H
497
458
  "internalValue": [32],
498
459
  "filterResult": [32],
499
460
  "filterFocus": [32],
461
+ "selectedOptions": [32],
500
462
  "setValue": [64],
501
463
  "reset": [64],
502
464
  "removeValue": [64],