@odx/foundation 1.0.0-beta.31 → 1.0.0-beta.32

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.
@@ -3487,7 +3487,7 @@ let OdxSelect = class extends ListboxFormControl {
3487
3487
  this.clear();
3488
3488
  });
3489
3489
  if (!isServer) {
3490
- this.addEventListener("change", () => {
3490
+ this.addEventListener("select", () => {
3491
3491
  if (this.multiple || this.autoSelect) return;
3492
3492
  this.dropdown.hidePopover();
3493
3493
  });
@@ -3507,13 +3507,13 @@ let OdxSelect = class extends ListboxFormControl {
3507
3507
  <div id="select-trigger" class="base" tabindex="0">
3508
3508
  <div class="value" odxPreventTextOverflow>
3509
3509
  ${when(
3510
- Array.from(this.selectedOptions).length,
3510
+ this.selectedOptions.length,
3511
3511
  () => this.renderSelectedOptions(),
3512
3512
  () => html`<slot name="placeholder">Select options</slot>`
3513
3513
  )}
3514
3514
  </div>
3515
3515
  ${when(
3516
- !this.multiple && __privateMethod$6(this, _OdxSelect_instances, isClearable_fn).call(this),
3516
+ __privateMethod$6(this, _OdxSelect_instances, isClearable_fn).call(this),
3517
3517
  () => html`<odx-icon-button icon="core::close" size="sm" tabindex="-1" variant="ghost" @click=${__privateGet$6(this, _handleClear)}></odx-icon-button>`
3518
3518
  )}
3519
3519
  <odx-icon class="indicator" name="core::chevron-down"></odx-icon>
@@ -3524,20 +3524,19 @@ let OdxSelect = class extends ListboxFormControl {
3524
3524
  `;
3525
3525
  }
3526
3526
  renderSelectedOptions() {
3527
- const selectedOptions = Array.from(this.selectedOptions);
3528
3527
  if (!this.multiple) {
3529
- return html`${selectedOptions[0]?.label}`;
3528
+ return html`${this.selectedOptions[0]?.label}`;
3530
3529
  }
3531
3530
  const renderChip = (option) => html`<odx-chip @remove=${() => __privateGet$6(this, _handleChipRemove).call(this, option)} removable tabindex="-1">${option.getTextLabel()}</odx-chip>`;
3532
3531
  return html`
3533
- ${repeat(selectedOptions.slice(0, this.maxVisibleSelectedOptions), renderChip)}
3534
- ${when(selectedOptions.length > this.maxVisibleSelectedOptions, () => html`<odx-chip>+${selectedOptions.length - this.maxVisibleSelectedOptions}</odx-chip>`)}
3532
+ ${repeat(this.selectedOptions.slice(0, this.maxVisibleSelectedOptions), renderChip)}
3533
+ ${when(this.selectedOptions.length > this.maxVisibleSelectedOptions, () => html`<odx-chip>+${this.selectedOptions.length - this.maxVisibleSelectedOptions}</odx-chip>`)}
3535
3534
  `;
3536
3535
  }
3537
3536
  };
3538
3537
  _OdxSelect_instances = new WeakSet();
3539
3538
  isClearable_fn = function() {
3540
- return !this.disabled && !this.readonly && !this.required && !!this.value;
3539
+ return !this.multiple && !this.disabled && !this.readonly && !this.required && this.selectedOptions.length > 0;
3541
3540
  };
3542
3541
  _handleSlotChange$2 = new WeakMap();
3543
3542
  _handleChipRemove = new WeakMap();
@@ -8,7 +8,7 @@ export declare abstract class ListboxFormControl<Option extends OptionControl> e
8
8
  autoSelect: boolean;
9
9
  multiple: boolean;
10
10
  value: string[] | string;
11
- get selectedOptions(): MapIterator<Option>;
11
+ get selectedOptions(): Option[];
12
12
  constructor();
13
13
  canAutoSelect(option: Option): boolean;
14
14
  canSelect(option: Option): boolean;
@@ -18,7 +18,6 @@ export declare abstract class OptionControl extends OptionControl_base implement
18
18
  selected: boolean;
19
19
  type?: 'checkbox' | null;
20
20
  getTextLabel(): string;
21
- toggle(force?: boolean): void;
22
21
  connectedCallback(): void;
23
22
  protected willUpdate(props: PropertyValueMap<this>): void;
24
23
  }
package/dist/main.js CHANGED
@@ -623,9 +623,6 @@ class OptionControl extends CanBeHighlighted(CanBeDisabled(CustomElement)) {
623
623
  getTextLabel() {
624
624
  return this.textContent?.trim() ?? "";
625
625
  }
626
- toggle(force) {
627
- this.toggleAttribute("odx-active", force ?? !this.hasAttribute("odx-active"));
628
- }
629
626
  connectedCallback() {
630
627
  super.connectedCallback();
631
628
  this.role ||= "option";
@@ -710,7 +707,7 @@ class ListboxFormControl extends FormControl(CustomElement) {
710
707
  #activeDecendants;
711
708
  #selectedOptions;
712
709
  get selectedOptions() {
713
- return this.#selectedOptions.values();
710
+ return Array.from(this.#selectedOptions.values());
714
711
  }
715
712
  canAutoSelect(option) {
716
713
  return this.autoSelect && !option.disabled && !this.multiple;
@@ -721,7 +718,7 @@ class ListboxFormControl extends FormControl(CustomElement) {
721
718
  toggleOption(option, state) {
722
719
  if (!this.canSelect(option)) return;
723
720
  const newState = state ?? (this.required && !this.multiple || !option.selected);
724
- if (this.disabled || newState === option.selected) return;
721
+ if (this.disabled) return;
725
722
  option.selected = newState;
726
723
  this.updateValue(option);
727
724
  if (newState) {
@@ -734,6 +731,7 @@ class ListboxFormControl extends FormControl(CustomElement) {
734
731
  this.id ||= getUniqueId(this.localName);
735
732
  }
736
733
  updateValue(option) {
734
+ const oldValue = this.value;
737
735
  if (this.multiple) {
738
736
  const value = typeof this.value === "string" ? [this.value].filter(Boolean) : this.value;
739
737
  this.value = option?.selected ? [...value, option.value] : value.filter((value2) => value2 !== option?.value);
@@ -743,11 +741,15 @@ class ListboxFormControl extends FormControl(CustomElement) {
743
741
  if (option) {
744
742
  this.#activeDecendants.select(option);
745
743
  }
746
- this.updateSelection();
744
+ this.emit("select", { composed: false });
745
+ if (oldValue === this.value) return;
747
746
  this.emit("change");
748
747
  }
749
748
  willUpdate(props) {
750
749
  super.willUpdate(props);
750
+ if (props.has("value")) {
751
+ this.updateSelection();
752
+ }
751
753
  if (props.has("multiple")) {
752
754
  this.#handleMultipleChange();
753
755
  }
@@ -768,6 +770,7 @@ class ListboxFormControl extends FormControl(CustomElement) {
768
770
  this.#selectedOptions.delete(option.value);
769
771
  }
770
772
  }
773
+ this.requestUpdate();
771
774
  }
772
775
  #handleBlur;
773
776
  #handleClick;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@odx/foundation",
3
3
  "description": "A library of Web Component building blocks for ODX",
4
- "version": "1.0.0-beta.31",
4
+ "version": "1.0.0-beta.32",
5
5
  "author": "Drägerwerk AG & Co.KGaA",
6
6
  "license": "SEE LICENSE IN LICENSE",
7
7
  "homepage": "https://odx.draeger.com",