UNPKG

@ngx-formly/material

Version:

Formly is a dynamic (JSON powered) form library for Angular that bring unmatched maintainability to your application's forms.

143 lines (137 loc) 7.25 kB
import * as i0 from '@angular/core'; import { ViewChild, ChangeDetectionStrategy, Component, NgModule } from '@angular/core'; import * as i3 from '@ngx-formly/core'; import { ɵobserve as _observe, FormlyModule } from '@ngx-formly/core'; import { FieldType, FormlyMatFormFieldModule } from '@ngx-formly/material/form-field'; import * as i2 from '@angular/material/radio'; import { MatRadioGroup, MatRadioModule } from '@angular/material/radio'; import * as i1 from '@angular/forms'; import { ReactiveFormsModule } from '@angular/forms'; import * as i4 from '@angular/common'; import { CommonModule } from '@angular/common'; import * as i5 from '@ngx-formly/core/select'; import { FormlySelectModule } from '@ngx-formly/core/select'; class FormlyFieldRadio extends FieldType { constructor() { super(...arguments); this.defaultOptions = { props: { hideFieldUnderline: true, floatLabel: 'always', tabindex: -1, }, }; } ngAfterViewInit() { this.focusObserver = _observe(this.field, ['focus'], ({ currentValue }) => { if (this.props.tabindex === -1 && currentValue && this.radioGroup._radios.length > 0) { // https://github.com/ngx-formly/ngx-formly/issues/2498 setTimeout(() => { const radio = this.radioGroup.selected ? this.radioGroup.selected : this.radioGroup._radios.first; radio.focus(); }); } }); } // TODO: find a solution to prevent scroll on focus onContainerClick() { } ngOnDestroy() { super.ngOnDestroy(); this.focusObserver && this.focusObserver.unsubscribe(); } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: FormlyFieldRadio, deps: null, target: i0.ɵɵFactoryTarget.Component }); } static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "18.2.13", type: FormlyFieldRadio, selector: "formly-field-mat-radio", viewQueries: [{ propertyName: "radioGroup", first: true, predicate: MatRadioGroup, descendants: true, static: true }], usesInheritance: true, ngImport: i0, template: ` <mat-radio-group [formControl]="formControl" [formlyAttributes]="field" [required]="required" [tabindex]="props.tabindex" > @for (option of props.options | formlySelectOptions: field | async; track $index; let i = $index) { <mat-radio-button [id]="id + '_' + i" [color]="props.color" [labelPosition]="props.labelPosition" [disabled]="option.disabled" [value]="option.value" > {{ option.label }} </mat-radio-button> } </mat-radio-group> `, isInline: true, dependencies: [{ kind: "directive", type: i1.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i1.RequiredValidator, selector: ":not([type=checkbox])[required][formControlName],:not([type=checkbox])[required][formControl],:not([type=checkbox])[required][ngModel]", inputs: ["required"] }, { kind: "directive", type: i1.FormControlDirective, selector: "[formControl]", inputs: ["formControl", "disabled", "ngModel"], outputs: ["ngModelChange"], exportAs: ["ngForm"] }, { kind: "directive", type: i2.MatRadioGroup, selector: "mat-radio-group", inputs: ["color", "name", "labelPosition", "value", "selected", "disabled", "required", "disabledInteractive"], outputs: ["change"], exportAs: ["matRadioGroup"] }, { kind: "component", type: i2.MatRadioButton, selector: "mat-radio-button", inputs: ["id", "name", "aria-label", "aria-labelledby", "aria-describedby", "disableRipple", "tabIndex", "checked", "value", "labelPosition", "disabled", "required", "color", "disabledInteractive"], outputs: ["change"], exportAs: ["matRadioButton"] }, { kind: "directive", type: i3.LegacyFormlyAttributes, selector: "[formlyAttributes]" }, { kind: "pipe", type: i4.AsyncPipe, name: "async" }, { kind: "pipe", type: i5.LegacyFormlySelectOptionsPipe, name: "formlySelectOptions" }], changeDetection: i0.ChangeDetectionStrategy.OnPush }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: FormlyFieldRadio, decorators: [{ type: Component, args: [{ selector: 'formly-field-mat-radio', template: ` <mat-radio-group [formControl]="formControl" [formlyAttributes]="field" [required]="required" [tabindex]="props.tabindex" > @for (option of props.options | formlySelectOptions: field | async; track $index; let i = $index) { <mat-radio-button [id]="id + '_' + i" [color]="props.color" [labelPosition]="props.labelPosition" [disabled]="option.disabled" [value]="option.value" > {{ option.label }} </mat-radio-button> } </mat-radio-group> `, changeDetection: ChangeDetectionStrategy.OnPush, }] }], propDecorators: { radioGroup: [{ type: ViewChild, args: [MatRadioGroup, { static: true }] }] } }); function withFormlyFieldRadio() { return { types: [ { name: 'radio', component: FormlyFieldRadio, wrappers: ['form-field'], }, ], }; } class FormlyMatRadioModule { static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: FormlyMatRadioModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); } static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "18.2.13", ngImport: i0, type: FormlyMatRadioModule, declarations: [FormlyFieldRadio], imports: [CommonModule, ReactiveFormsModule, MatRadioModule, FormlyMatFormFieldModule, FormlySelectModule, i3.FormlyModule] }); } static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: FormlyMatRadioModule, imports: [CommonModule, ReactiveFormsModule, MatRadioModule, FormlyMatFormFieldModule, FormlySelectModule, FormlyModule.forChild(withFormlyFieldRadio())] }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: FormlyMatRadioModule, decorators: [{ type: NgModule, args: [{ declarations: [FormlyFieldRadio], imports: [ CommonModule, ReactiveFormsModule, MatRadioModule, FormlyMatFormFieldModule, FormlySelectModule, FormlyModule.forChild(withFormlyFieldRadio()), ], }] }] }); /** * Generated bundle index. Do not edit. */ export { FormlyFieldRadio, FormlyMatRadioModule, withFormlyFieldRadio }; //# sourceMappingURL=ngx-formly-material-radio.mjs.map