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

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 (37) hide show
  1. package/dist/cjs/loader.cjs.js +1 -1
  2. package/dist/cjs/tds-dropdown_2.cjs.entry.js +85 -109
  3. package/dist/cjs/tds-link.cjs.entry.js +5 -3
  4. package/dist/cjs/tds-popover-core.cjs.entry.js +1 -1
  5. package/dist/cjs/tegel.cjs.js +1 -1
  6. package/dist/collection/components/dropdown/dropdown.js +89 -111
  7. package/dist/collection/components/link/link.css +7 -1
  8. package/dist/collection/components/link/link.js +22 -2
  9. package/dist/collection/components/popover-core/tds-popover-core.css +18 -13
  10. package/dist/components/{p-dcfecf4d.js → p-5eaae628.js} +1 -1
  11. package/dist/components/{p-e02b091c.js → p-a7a89410.js} +1 -1
  12. package/dist/components/{p-097af62b.js → p-aa12ddb9.js} +86 -109
  13. package/dist/components/tds-dropdown.js +1 -1
  14. package/dist/components/tds-header-dropdown.js +2 -2
  15. package/dist/components/tds-header-launcher.js +2 -2
  16. package/dist/components/tds-link.js +7 -4
  17. package/dist/components/tds-popover-canvas.js +1 -1
  18. package/dist/components/tds-popover-core.js +1 -1
  19. package/dist/components/tds-popover-menu.js +1 -1
  20. package/dist/components/tds-table-footer.js +1 -1
  21. package/dist/components/tds-tooltip.js +1 -1
  22. package/dist/esm/loader.js +1 -1
  23. package/dist/esm/tds-dropdown_2.entry.js +85 -109
  24. package/dist/esm/tds-link.entry.js +5 -3
  25. package/dist/esm/tds-popover-core.entry.js +1 -1
  26. package/dist/esm/tegel.js +1 -1
  27. package/dist/tegel/{p-590b5f55.entry.js → p-370f899b.entry.js} +1 -1
  28. package/dist/tegel/p-be8d494d.entry.js +1 -0
  29. package/dist/tegel/p-e97a2700.entry.js +1 -0
  30. package/dist/tegel/tegel.css +1 -1
  31. package/dist/tegel/tegel.esm.js +1 -1
  32. package/dist/types/components/dropdown/dropdown.d.ts +8 -2
  33. package/dist/types/components/link/link.d.ts +2 -0
  34. package/dist/types/components.d.ts +8 -0
  35. package/package.json +1 -1
  36. package/dist/tegel/p-a0925278.entry.js +0 -1
  37. package/dist/tegel/p-c3513f1f.entry.js +0 -1
@@ -69,39 +69,13 @@ const TdsDropdown = class {
69
69
  this.tdsBlur = createEvent(this, "tdsBlur", 6);
70
70
  this.tdsInput = createEvent(this, "tdsInput", 6);
71
71
  this.tdsValueChange = createEvent(this, "tdsValueChange", 6);
72
- this.handleChange = () => {
73
- const value = Array.isArray(this.value) ? this.value.join(',') : this.value;
74
- this.tdsChange.emit({
75
- name: this.name,
76
- value: value !== null && value !== void 0 ? value : null,
77
- });
78
- };
79
72
  this.setDefaultOption = () => {
80
73
  if (this.defaultValue) {
81
- const children = Array.from(this.host.children).filter((element) => element.tagName === 'TDS-DROPDOWN-OPTION');
82
- if (children.length === 0) {
83
- console.warn('TDS DROPDOWN: No options found. Disregard if loading data asynchronously.');
84
- return;
85
- }
86
74
  const defaultValues = this.multiselect
87
75
  ? new Set(this.defaultValue.split(','))
88
76
  : [this.defaultValue];
89
- const childrenMap = new Map(children.map((element) => [element.value, element]));
90
- const matchedValues = Array.from(defaultValues).filter((value) => {
91
- const element = childrenMap.get(value);
92
- if (element) {
93
- element.setSelected(true);
94
- return true;
95
- }
96
- return false;
97
- });
98
- if (matchedValues.length > 0) {
99
- this.value = [...new Set(this.value ? [...this.value, ...matchedValues] : matchedValues)];
100
- this.setValueAttribute();
101
- }
102
- else {
103
- console.warn(`TDS DROPDOWN: No matching option found for defaultValue "${this.defaultValue}"`);
104
- }
77
+ const normalizedValues = Array.from(defaultValues);
78
+ this.updateDropdownState(normalizedValues);
105
79
  }
106
80
  };
107
81
  this.getChildren = () => {
@@ -113,12 +87,12 @@ const TdsDropdown = class {
113
87
  return tdsDropdownOptions;
114
88
  };
115
89
  this.getSelectedChildren = () => {
116
- if (!this.value)
90
+ if (this.selectedOptions.length === 0)
117
91
  return [];
118
- const valueArray = Array.isArray(this.value) ? this.value : [this.value];
119
- return valueArray
92
+ return this.selectedOptions
120
93
  .map((stringValue) => {
121
- const matchingElement = this.getChildren().find((element) => element.value === stringValue);
94
+ var _a;
95
+ const matchingElement = (_a = this.getChildren()) === null || _a === void 0 ? void 0 : _a.find((element) => element.value === stringValue);
122
96
  return matchingElement;
123
97
  })
124
98
  .filter(Boolean);
@@ -135,13 +109,11 @@ const TdsDropdown = class {
135
109
  return labels === null || labels === void 0 ? void 0 : labels.join(', ');
136
110
  };
137
111
  this.setValueAttribute = () => {
138
- var _a;
139
- if (!this.value || ((_a = this.value) === null || _a === void 0 ? void 0 : _a.toString()) === '') {
112
+ if (this.selectedOptions.length === 0) {
140
113
  this.host.removeAttribute('value');
141
114
  }
142
115
  else {
143
- const valueArray = Array.isArray(this.value) ? this.value : [this.value];
144
- this.host.setAttribute('value', valueArray.map((val) => val).toString());
116
+ this.host.setAttribute('value', this.selectedOptions.join(','));
145
117
  }
146
118
  };
147
119
  this.getOpenDirection = () => {
@@ -236,88 +208,94 @@ const TdsDropdown = class {
236
208
  this.normalizeText = true;
237
209
  this.noResultText = 'No result';
238
210
  this.defaultValue = undefined;
239
- this.value = undefined;
211
+ this.value = null;
240
212
  this.open = false;
241
213
  this.internalValue = undefined;
242
214
  this.filterResult = undefined;
243
215
  this.filterFocus = undefined;
216
+ this.selectedOptions = [];
244
217
  }
245
218
  handleValueChange(newValue) {
246
- // Convert both newValue and this.value to arrays for comparison
247
- const newValueArray = Array.isArray(newValue) ? newValue : newValue ? [newValue] : [];
248
- const currentValueArray = Array.isArray(this.value)
249
- ? this.value
250
- : this.value
251
- ? [this.value]
252
- : [];
253
- // Check if the new value is different from the current value
254
- const hasChanged = newValueArray.length !== currentValueArray.length ||
255
- newValueArray.some((val, index) => val !== currentValueArray[index]);
256
- if (hasChanged) {
257
- // Proceed with updating selections and emitting changes
258
- this.updateSelections(newValueArray);
259
- this.handleChange();
219
+ // Normalize to array
220
+ const normalizedValue = this.normalizeValue(newValue);
221
+ // Only update if actually changed
222
+ if (this.hasValueChanged(normalizedValue, this.selectedOptions)) {
223
+ this.updateDropdownState(normalizedValue);
260
224
  }
261
225
  }
262
- updateSelections(valueArray) {
263
- // Reset current selections
264
- this.getChildren().forEach((element) => {
265
- element.setSelected(false);
266
- });
267
- if (valueArray) {
268
- // Validate and filter values
269
- const validValues = valueArray.filter((val) => {
270
- const optionExists = this.getChildren().some((element) => element.value === val);
271
- if (!optionExists) {
272
- console.warn(`Option with value "${val}" does not exist`);
273
- }
274
- return optionExists;
275
- });
276
- // Update internal state and selections
277
- this.internalValue = validValues.join(', ');
278
- this.getChildren().forEach((element) => {
279
- if (validValues.includes(element.value)) {
280
- element.setSelected(true);
281
- }
282
- });
283
- // Update value prop with validated values
284
- if (this.multiselect) {
285
- this.value = validValues;
286
- }
287
- else {
288
- this.value = validValues[0] || null;
289
- }
290
- }
291
- else {
292
- // Handle null/undefined case
293
- this.internalValue = '';
294
- this.value = this.multiselect ? [] : null;
226
+ normalizeValue(value) {
227
+ if (!value)
228
+ return [];
229
+ // For multiselect, keep array. For single select, wrap in array
230
+ if (this.multiselect) {
231
+ return Array.isArray(value) ? value : value.split(',');
295
232
  }
296
- // Emit change events
297
- this.handleChange();
298
- // Update filter input if present
233
+ return Array.isArray(value) ? value : [value];
234
+ }
235
+ hasValueChanged(newValue, currentValue) {
236
+ if (newValue.length !== currentValue.length)
237
+ return true;
238
+ return newValue.some((val) => !currentValue.includes(val));
239
+ }
240
+ updateDropdownState(values) {
241
+ // Update internal state
242
+ this.selectedOptions = this.validateValues(values);
243
+ // Then update the value prop to match
244
+ this.value = this.multiselect ? this.selectedOptions : this.selectedOptions[0] || null;
245
+ // Update DOM
246
+ this.updateOptionElements();
247
+ // Update display value
248
+ this.updateDisplayValue();
249
+ // Emit change event
250
+ this.emitChange();
251
+ // Update value attribute
252
+ this.setValueAttribute();
253
+ }
254
+ validateValues(values) {
255
+ return values.filter((val) => {
256
+ var _a;
257
+ const isValid = (_a = this.getChildren()) === null || _a === void 0 ? void 0 : _a.some((element) => element.value === val);
258
+ if (!isValid) {
259
+ console.warn(`Option with value "${val}" does not exist`);
260
+ }
261
+ return isValid;
262
+ });
263
+ }
264
+ updateOptionElements() {
265
+ var _a;
266
+ (_a = this.getChildren()) === null || _a === void 0 ? void 0 : _a.forEach((element) => {
267
+ element.setSelected(this.selectedOptions.includes(element.value));
268
+ });
269
+ }
270
+ updateDisplayValue() {
271
+ this.internalValue = this.getSelectedChildrenLabels().join(', ');
299
272
  if (this.filter && this.inputElement) {
300
273
  this.inputElement.value = this.internalValue;
301
274
  }
302
- this.setValueAttribute();
275
+ }
276
+ emitChange() {
277
+ const value = this.multiselect
278
+ ? this.selectedOptions.join(',')
279
+ : this.selectedOptions[0] || null;
280
+ this.tdsChange.emit({
281
+ name: this.name,
282
+ value: value !== null && value !== void 0 ? value : null,
283
+ });
303
284
  }
304
285
  async setValue(value) {
305
- this.value = value;
286
+ const normalizedValue = this.normalizeValue(value);
287
+ this.updateDropdownState(normalizedValue);
306
288
  return this.getSelectedChildren().map((element) => ({
307
289
  value: element.value,
308
290
  label: element.textContent.trim(),
309
291
  }));
310
292
  }
311
293
  async reset() {
312
- this.value = this.multiselect ? [] : null;
294
+ this.updateDropdownState([]);
313
295
  }
314
296
  async removeValue(oldValue) {
315
- if (this.multiselect && Array.isArray(this.value)) {
316
- this.value = this.value.filter((v) => v !== oldValue);
317
- }
318
- else {
319
- this.value = null;
320
- }
297
+ const newValues = this.selectedOptions.filter((v) => v !== oldValue);
298
+ this.updateDropdownState(newValues);
321
299
  }
322
300
  /** Method that forces focus on the input element. */
323
301
  async focusElement() {
@@ -377,9 +355,9 @@ const TdsDropdown = class {
377
355
  }
378
356
  componentWillLoad() {
379
357
  if (this.defaultValue && !this.value) {
380
- this.value = this.defaultValue;
358
+ const initialValue = this.multiselect ? this.defaultValue.split(',') : [this.defaultValue];
359
+ this.updateDropdownState(initialValue);
381
360
  }
382
- this.setDefaultOption();
383
361
  }
384
362
  /** Method to handle slot changes */
385
363
  handleSlotChange() {
@@ -391,10 +369,10 @@ const TdsDropdown = class {
391
369
  }
392
370
  async appendValue(value) {
393
371
  if (this.multiselect) {
394
- this.value = Array.isArray(this.value) ? [...this.value, value] : [value];
372
+ this.updateDropdownState([...this.selectedOptions, value]);
395
373
  }
396
374
  else {
397
- this.value = value;
375
+ this.updateDropdownState([value]);
398
376
  }
399
377
  }
400
378
  componentDidRender() {
@@ -410,10 +388,8 @@ const TdsDropdown = class {
410
388
  }
411
389
  }
412
390
  render() {
413
- var _a, _b, _c;
414
- const valueArray = Array.isArray(this.value) ? this.value : this.value ? [this.value] : [];
415
- appendHiddenInput(this.host, this.name, valueArray.map((value) => value).toString(), this.disabled);
416
- 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: {
391
+ appendHiddenInput(this.host, this.name, this.selectedOptions.join(','), this.disabled);
392
+ return (h(Host, { key: 'b80b938a7e06df4883e939cf9cf06cbb5d2dc12b', role: "select", class: `${this.modeVariant ? `tds-mode-variant-${this.modeVariant}` : ''}` }, this.label && this.labelPosition === 'outside' && (h("div", { key: '75172f55ac3adc34a050bbeba543165b6c6ec445', class: `label-outside ${this.disabled ? 'disabled' : ''}` }, this.label)), h("div", { key: 'd0498b07c2446b7ccde5bd09a95157454ffc2331', class: `dropdown-select ${this.size} ${this.disabled ? 'disabled' : ''}` }, this.filter ? (h("div", { class: {
417
393
  filter: true,
418
394
  focus: this.filterFocus,
419
395
  disabled: this.disabled,
@@ -421,7 +397,7 @@ const TdsDropdown = class {
421
397
  } }, h("div", { class: "value-wrapper" }, this.label && this.labelPosition === 'inside' && this.placeholder && (h("div", { class: `label-inside ${this.size}` }, this.label)), this.label && this.labelPosition === 'inside' && !this.placeholder && (h("div", { class: `
422
398
  label-inside-as-placeholder
423
399
  ${this.size}
424
- ${((_a = this.value) === null || _a === void 0 ? void 0 : _a.length) ? 'selected' : ''}
400
+ ${this.selectedOptions.length ? 'selected' : ''}
425
401
  ` }, this.label)), h("input", {
426
402
  // eslint-disable-next-line no-return-assign
427
403
  ref: (inputEl) => (this.inputElement = inputEl), class: `${this.labelPosition === 'inside' ? 'placeholder' : ''}`, type: "text", placeholder: this.filterFocus ? '' : this.placeholder, value: this.multiselect && this.filterFocus ? '' : this.getValue(), disabled: this.disabled, onInput: (event) => this.handleFilter(event), onBlur: (event) => {
@@ -448,14 +424,14 @@ const TdsDropdown = class {
448
424
  this.open = false;
449
425
  }
450
426
  }, class: `
451
- ${this.value ? 'value' : 'placeholder'}
427
+ ${this.selectedOptions.length ? 'value' : 'placeholder'}
452
428
  ${this.open ? 'open' : 'closed'}
453
429
  ${this.error ? 'error' : ''}
454
430
  `, disabled: this.disabled }, h("div", { class: `value-wrapper ${this.size}` }, this.label && this.labelPosition === 'inside' && this.placeholder && (h("div", { class: `label-inside ${this.size}` }, this.label)), this.label && this.labelPosition === 'inside' && !this.placeholder && (h("div", { class: `
455
431
  label-inside-as-placeholder
456
432
  ${this.size}
457
- ${((_b = this.value) === null || _b === void 0 ? void 0 : _b.length) ? 'selected' : ''}
458
- ` }, 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: {
433
+ ${this.selectedOptions.length ? 'selected' : ''}
434
+ ` }, this.label)), h("div", { class: `placeholder ${this.size}` }, this.selectedOptions.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: '999a08cee6035f37217270681b58411badc1596d', ref: (element) => (this.dropdownList = element), class: {
459
435
  'dropdown-list': true,
460
436
  [this.size]: true,
461
437
  [this.getOpenDirection()]: true,
@@ -464,7 +440,7 @@ const TdsDropdown = class {
464
440
  'closed': !this.open,
465
441
  [`animation-enter-${this.animation}`]: this.animation !== 'none' && this.open,
466
442
  [`animation-exit-${this.animation}`]: this.animation !== 'none' && !this.open,
467
- } }, 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))));
443
+ } }, h("slot", { key: 'f6e55be5581a1b5a24da4643508c4fe76767c9c7', onSlotchange: () => this.handleSlotChange() }), this.filterResult === 0 && this.noResultText !== '' && (h("div", { key: '6184dce7e827ee6c2c0403e8531ea8ac782e3073', class: `no-result ${this.size}` }, this.noResultText))), this.helper && (h("div", { key: '33bd5d3695247cfaaa66bb67b6ac6a5ced795c72', class: `helper ${this.error ? 'error' : ''} ${this.disabled ? 'disabled' : ''}` }, this.error && h("tds-icon", { key: '6f3681a038fc95bb90e7877c54eff0b4c807b877', name: "error", size: "16px" }), this.helper))));
468
444
  }
469
445
  get host() { return getElement(this); }
470
446
  static get watchers() { return {
@@ -1,6 +1,6 @@
1
1
  import { r as registerInstance, h, g as getElement } from './index-51d04e39.js';
2
2
 
3
- const linkCss = ":host{display:inline}:host ::slotted(*){all:unset;cursor:pointer;outline:none;color:var(--tds-link);text-decoration:underline}:host ::slotted(*:focus-visible){color:var(--tds-link-focus);text-decoration:none;outline:2px solid var(--tds-link-focus);outline-offset:-2px}:host ::slotted(*:active){color:var(--tds-link);text-decoration:underline;text-decoration-color:var(--tds-link)}:host ::slotted(*:hover){color:var(--tds-link-hover);text-decoration:underline;text-decoration-color:var(--tds-link-hover)}:host ::slotted(*:visited){color:var(--tds-link-visited);text-decoration-color:var(--tds-link-visited)}.disabled ::slotted(*){color:var(--tds-link-disabled);text-decoration-color:var(--tds-link-disabled);pointer-events:none}.no-underline ::slotted(*){text-decoration:none}.no-underline:hover ::slotted(*){text-decoration:none}";
3
+ const linkCss = ":host{display:inline}:host ::slotted(*){all:unset;cursor:pointer;outline:none;color:var(--tds-link);text-decoration:underline}:host ::slotted(*:focus-visible){color:var(--tds-link-focus);text-decoration:none;outline:2px solid var(--tds-link-focus);outline-offset:-2px}:host ::slotted(*:active){color:var(--tds-link);text-decoration:underline;text-decoration-color:var(--tds-link)}:host ::slotted(*:hover){color:var(--tds-link-hover);text-decoration:underline;text-decoration-color:var(--tds-link-hover)}:host ::slotted(*:visited){color:var(--tds-link-visited);text-decoration-color:var(--tds-link-visited)}.disabled ::slotted(*),.disabled ::slotted(*:visited){color:var(--tds-link-disabled);text-decoration-color:var(--tds-link-disabled);pointer-events:none}.no-underline ::slotted(*){text-decoration:none}.no-underline:hover ::slotted(*){text-decoration:none}.standalone ::slotted(*){font:var(--tds-detail-02);letter-spacing:var(--tds-detail-02-ls)}";
4
4
  const TdsLinkStyle0 = linkCss;
5
5
 
6
6
  const TdsLink = class {
@@ -8,15 +8,17 @@ const TdsLink = class {
8
8
  registerInstance(this, hostRef);
9
9
  this.disabled = false;
10
10
  this.underline = true;
11
+ this.standalone = false;
11
12
  }
12
13
  connectedCallback() {
13
14
  this.host.children[0].classList.add('tds-link-component');
14
15
  }
15
16
  render() {
16
- return (h("span", { key: 'd812a60488213cdd31c3ace934ae93c3b3781cf9', class: `
17
+ return (h("span", { key: '619f52601e4716a34fd39752704acf06acd94dd8', class: `
17
18
  ${this.disabled ? 'disabled' : ''}
18
19
  ${!this.underline ? 'no-underline' : ''}
19
- ` }, h("slot", { key: '2b9675a2abd7b7c16200cda28fa5ded499c03fcd' })));
20
+ ${this.standalone ? 'standalone' : ''}
21
+ ` }, h("slot", { key: '636596dae6e69aff2f10666e86fb965e46efb059' })));
20
22
  }
21
23
  get host() { return getElement(this); }
22
24
  };