@odx/foundation 1.0.0-beta.80 → 1.0.0-beta.81

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.
@@ -735,17 +735,13 @@ const _OdxCheckboxGroup = class _OdxCheckboxGroup extends CheckboxGroupFormContr
735
735
  super(...arguments);
736
736
  this.layout = CheckboxGroupLayout.VERTICAL;
737
737
  this.#handleSlotChange = () => {
738
- for (const control of this.groupControls) {
739
- control.addEventListener("change", this.#handleGroupControlChange);
740
- }
738
+ this.groupControl?.removeEventListener("change", this.#handleGroupControlChange);
739
+ this.groupControl?.addEventListener("change", this.#handleGroupControlChange);
741
740
  };
742
741
  this.#handleGroupControlChange = (event) => {
743
- if (!this.isControl(event.target)) return;
742
+ if (!this.isGroupControl(event.target)) return;
744
743
  event.stopImmediatePropagation();
745
744
  this.updateValue(event.target.checked ? this.controls.map((control) => control.value) : [], true);
746
- for (const groupControl of this.childGroups.flatMap((group) => group.groupControls)) {
747
- groupControl.checked = event.target.checked;
748
- }
749
745
  };
750
746
  }
751
747
  static {
@@ -6,11 +6,14 @@ export declare abstract class CheckboxGroupFormControl extends FormControl<strin
6
6
  private elements;
7
7
  protected get childGroups(): CheckboxGroupFormControl[];
8
8
  get controls(): CheckboxFormControl[];
9
- get groupControls(): CheckboxFormControl[];
9
+ get selectedControls(): CheckboxFormControl[];
10
+ get groupControl(): CheckboxFormControl | null;
10
11
  value: string[];
11
12
  constructor();
13
+ protected firstUpdated(_changedProperties: PropertyValues): Promise<void>;
12
14
  toFormValue(): FormData;
13
15
  protected isControl(element: unknown): element is CheckboxFormControl;
16
+ protected isGroupControl(element: unknown): element is CheckboxFormControl;
14
17
  protected isControlChecked(control: CheckboxFormControl): boolean;
15
18
  protected updated(props: PropertyValues<this>): void;
16
19
  protected updateControls(updateFn: (control: CheckboxFormControl, index: number) => void): void;
@@ -4,7 +4,7 @@ export declare function forwardEvent(target: HTMLElement, eventInit?: EventInit)
4
4
  export declare function getElementFromEvent<T = HTMLElement>(event: Event, filterFn: (node: Element) => boolean): T;
5
5
  export declare function waitForAnimations(element?: Element | null, subtree?: boolean): Promise<Animation[]>;
6
6
  export declare function toAriaBooleanAttribute(value: boolean, removeOnFalse?: boolean): 'true' | 'false';
7
- export declare function toPx(value?: string | number | null): string | null;
7
+ export declare function toPx(value?: number | null): string | null;
8
8
  export interface GetAssignedElementOptions {
9
9
  slot?: string;
10
10
  selector?: string;
package/dist/main.js CHANGED
@@ -68,9 +68,8 @@ function toAriaBooleanAttribute(value, removeOnFalse = true) {
68
68
  return removeOnFalse && value === false ? null : String(value);
69
69
  }
70
70
  function toPx(value) {
71
- const coercedValue = Number(value);
72
- if (value == null || value === "" || Number.isNaN(coercedValue)) return null;
73
- return `${round(coercedValue, 2)}px`;
71
+ if (value == null || Number.isNaN(value)) return null;
72
+ return `${round(value, 2)}px`;
74
73
  }
75
74
  function getAssignedElement(root, options) {
76
75
  const { slot, selector } = options ?? {};
@@ -120,10 +119,10 @@ const CanBeDisabled = (superClass) => {
120
119
  this.ariaDisabled = toAriaBooleanAttribute(this.disabled);
121
120
  if (this.disabled) {
122
121
  this.tabIndex = -1;
123
- } else if (this.#initialTabIndex !== void 0) {
124
- this.tabIndex = this.#initialTabIndex;
125
- } else {
122
+ } else if (this.#initialTabIndex === void 0) {
126
123
  this.removeAttribute("tabindex");
124
+ } else {
125
+ this.tabIndex = this.#initialTabIndex;
127
126
  }
128
127
  }
129
128
  }
@@ -244,7 +243,7 @@ class CheckboxFormControl extends FormControl {
244
243
  const newState = state ?? !currentState;
245
244
  if (this.disabled || this.readonly || newState === currentState) return;
246
245
  this.checked = newState;
247
- if (!(emitEvent && this.emit("change"))) return;
246
+ if (!(emitEvent && this.emit("change", { bubbles: true }))) return;
248
247
  this.checked = currentState;
249
248
  }
250
249
  connectedCallback() {
@@ -272,16 +271,20 @@ const _CheckboxGroupFormControl = class _CheckboxGroupFormControl extends FormCo
272
271
  super();
273
272
  this.value = [];
274
273
  this.#handleChangeEvent = (event) => {
275
- const { target } = event;
276
- if (!this.isControl(target)) return;
277
- if (target.checked) {
278
- this.updateValue([...this.value, target.value], true);
279
- return;
274
+ if (this.isControl(event.target)) {
275
+ this.#handleControlChange(event);
276
+ }
277
+ };
278
+ this.#handleControlChange = (event) => {
279
+ if (!this.isControl(event.target)) return;
280
+ if (event.target.checked) {
281
+ this.updateValue([...this.value, event.target.value], true);
282
+ } else {
283
+ this.updateValue(
284
+ this.value.filter((value) => value !== event.target.value),
285
+ true
286
+ );
280
287
  }
281
- this.updateValue(
282
- this.value.filter((value) => value !== target.value),
283
- true
284
- );
285
288
  };
286
289
  if (!isServer) {
287
290
  this.addEventListener("change", this.#handleChangeEvent);
@@ -293,8 +296,15 @@ const _CheckboxGroupFormControl = class _CheckboxGroupFormControl extends FormCo
293
296
  get controls() {
294
297
  return this.#findControls((element) => !element.hasAttribute(GROUP_CONTROL_SELECTOR)).concat(this.childGroups.flatMap((group) => group.controls));
295
298
  }
296
- get groupControls() {
297
- return this.#findControls((element) => element.hasAttribute(GROUP_CONTROL_SELECTOR));
299
+ get selectedControls() {
300
+ return this.controls.filter((control) => this.isControlChecked(control));
301
+ }
302
+ get groupControl() {
303
+ return this.#findControls((element) => element.hasAttribute(GROUP_CONTROL_SELECTOR))[0] ?? null;
304
+ }
305
+ async firstUpdated(_changedProperties) {
306
+ await 0;
307
+ this.value = this.controls.filter((control) => control.checked).map((control) => control.value);
298
308
  }
299
309
  toFormValue() {
300
310
  const formData = new FormData();
@@ -306,6 +316,9 @@ const _CheckboxGroupFormControl = class _CheckboxGroupFormControl extends FormCo
306
316
  isControl(element) {
307
317
  return element instanceof CheckboxFormControl;
308
318
  }
319
+ isGroupControl(element) {
320
+ return this.isControl(element) && element.hasAttribute(GROUP_CONTROL_SELECTOR);
321
+ }
309
322
  isControlChecked(control) {
310
323
  return this.value.includes(control.value);
311
324
  }
@@ -315,10 +328,10 @@ const _CheckboxGroupFormControl = class _CheckboxGroupFormControl extends FormCo
315
328
  this.updateControls((control) => {
316
329
  control.checked = this.isControlChecked(control);
317
330
  });
318
- for (const groupControl of this.groupControls) {
319
- if (groupControl instanceof CheckboxFormControl && "indeterminate" in groupControl) {
320
- groupControl.indeterminate = this.value.length > 0 && this.value.length < this.controls.length;
321
- groupControl.checked = this.controls.length > 0 && this.value.length === this.controls.length;
331
+ if (this.groupControl) {
332
+ this.groupControl.checked = this.controls.length > 0 && this.value.length === this.controls.length;
333
+ if ("indeterminate" in this.groupControl) {
334
+ this.groupControl.indeterminate = this.value.length > 0 && this.value.length < this.controls.length;
322
335
  }
323
336
  }
324
337
  }
@@ -343,13 +356,18 @@ const _CheckboxGroupFormControl = class _CheckboxGroupFormControl extends FormCo
343
356
  }
344
357
  updateValue(value, dispatchEvent) {
345
358
  this.value = value;
359
+ for (const group of this.childGroups) {
360
+ const groupValue = this.value.filter((value2) => group.controls.some((control) => control.value === value2));
361
+ group.updateValue(groupValue, false);
362
+ }
346
363
  if (!dispatchEvent) return;
347
- this.emit("change");
364
+ this.emit("change", { bubbles: true });
348
365
  }
349
- #handleChangeEvent;
350
366
  #findControls(predicate) {
351
367
  return this.elements.filter((element) => this.isControl(element) && predicate(element));
352
368
  }
369
+ #handleChangeEvent;
370
+ #handleControlChange;
353
371
  };
354
372
  __decorateClass([
355
373
  queryAssignedElements({ flatten: true })
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.80",
4
+ "version": "1.0.0-beta.81",
5
5
  "author": "Drägerwerk AG & Co.KGaA",
6
6
  "license": "SEE LICENSE IN LICENSE",
7
7
  "homepage": "https://odx.draeger.com",