All files / formly/wrapper si-formly-form-field-provider.directive.ts

90% Statements 9/10
75% Branches 3/4
100% Functions 3/3
88.88% Lines 8/9

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31                        1x 18x   18x   18x 16x 16x     16x         18x      
/**
 * Copyright (c) Siemens 2016 - 2025
 * SPDX-License-Identifier: MIT
 */
import { Directive, OnChanges, computed, input } from '@angular/core';
import { FormlyFieldConfig } from '@ngx-formly/core';
import { SI_FORM_ITEM_CONTROL, SiFormItemControl } from '@siemens/element-ng/form';
 
@Directive({
  selector: '[siFormlyFormFieldProvider]',
  providers: [{ provide: SI_FORM_ITEM_CONTROL, useExisting: SiFormlyFormFieldProviderDirective }]
})
export class SiFormlyFormFieldProviderDirective implements SiFormItemControl, OnChanges {
  readonly field = input.required<FormlyFieldConfig>();
 
  readonly id = computed(() => this.field().id);
  isFormCheck?: boolean;
  readonly labelledby = computed(() => {
    const fieldValue = this.field();
    Iif (fieldValue.props?.useAriaLabel) {
      return fieldValue.id + '-label';
    } else {
      return undefined;
    }
  });
 
  ngOnChanges(): void {
    this.isFormCheck = this.field().type === 'checkbox' || this.field().type === 'boolean';
  }
}