Skip to content

Commit

Permalink
fix(core): remove additionalProps from FormlyFieldProps interface (#3295
Browse files Browse the repository at this point in the history
)

fix #3242
  • Loading branch information
aitboudad committed May 14, 2022
1 parent 82fdf9c commit 05891df
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 22 deletions.
5 changes: 1 addition & 4 deletions src/core/src/lib/extensions/core/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,7 @@ export class CoreExtension implements FormlyExtension {
}

private initFieldProps(field: FormlyFieldConfigCache) {
if (!field.props) {
field.props = field.templateOptions;
}

field.props ??= field.templateOptions;
Object.defineProperty(field, 'templateOptions', {
get: () => field.props,
set: (props) => (field.props = props),
Expand Down
11 changes: 6 additions & 5 deletions src/core/src/lib/models/fieldconfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { FieldWrapper } from '../templates/field.wrapper';
import { ValidationMessageOption } from '../models';
import { Type } from '@angular/core';

export interface FormlyFieldConfig {
export interface FormlyFieldConfig<Props = FormlyFieldProps & { [additionalProperties: string]: any }> {
/**
* The key that relates to the model. This will link the field value to the model
*/
Expand Down Expand Up @@ -34,10 +34,10 @@ export interface FormlyFieldConfig {
/**
* This is reserved for the templates. Any template-specific options go in here. Look at your specific template implementation to know the options required for this.
*/
props?: FormlyFieldProps;
props?: Props;

/** @deprecated Use `props` instead. */
templateOptions?: FormlyFieldConfig['props'];
templateOptions?: FormlyTemplateOptions;

/**
* An object with a few useful properties
Expand Down Expand Up @@ -203,7 +203,9 @@ export interface FormlyFieldConfig {
export type FormlyAttributeEvent = (field: FormlyFieldConfig, event?: any) => void;

/** @deprecated */
export type FormlyTemplateOptions = FormlyFieldProps;
export interface FormlyTemplateOptions extends FormlyFieldProps {
[additionalProperties: string]: any;
}

export interface FormlyFieldProps {
type?: string;
Expand Down Expand Up @@ -239,7 +241,6 @@ export interface FormlyFieldProps {
click?: FormlyAttributeEvent;
change?: FormlyAttributeEvent;
keypress?: FormlyAttributeEvent;
[additionalProperties: string]: any;
}

export type FormlyHookFn = (field?: FormlyFieldConfig) => void;
Expand Down
8 changes: 4 additions & 4 deletions src/core/src/lib/templates/field.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import { Input, Directive } from '@angular/core';
import { FormControl, FormGroup } from '@angular/forms';
import { FormlyFieldConfig } from '../models';

export interface FieldTypeConfig extends FormlyFieldConfig {
export interface FieldTypeConfig<T = FormlyFieldConfig['props']> extends FormlyFieldConfig<T> {
formControl: FormControl;
props: NonNullable<Required<FormlyFieldConfig>['props']>;
props: NonNullable<T>;
}

export interface FieldGroupTypeConfig extends FormlyFieldConfig {
export interface FieldGroupTypeConfig<T = FormlyFieldConfig['props']> extends FormlyFieldConfig<T> {
formControl: FormGroup;
props: NonNullable<Required<FormlyFieldConfig>['props']>;
props: NonNullable<T>;
}

@Directive()
Expand Down
4 changes: 2 additions & 2 deletions src/core/src/lib/templates/formly.attributes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
Inject,
OnDestroy,
} from '@angular/core';
import { FormlyFieldConfig, FormlyFieldConfigCache, FormlyFieldProps } from '../models';
import { FormlyFieldConfig, FormlyFieldConfigCache } from '../models';
import { defineHiddenProp, FORMLY_VALIDATORS, observe, IObserver } from '../utils';
import { DOCUMENT } from '@angular/common';

Expand Down Expand Up @@ -51,7 +51,7 @@ export class FormlyAttributes implements OnChanges, DoCheck, OnDestroy {
};

private get props() {
return this.field.props || ({} as FormlyFieldProps);
return this.field.props || ({} as FormlyFieldConfigCache['props']);
}

private get fieldAttrElements(): ElementRef[] {
Expand Down
5 changes: 2 additions & 3 deletions src/ui/material/form-field/src/field.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,13 @@ export abstract class FieldType<F extends FormlyFieldConfig = FormlyFieldConfig>
(control.ngControl.valueAccessor as any)['_formField'] = this.formField;
}

['Prefix', 'Suffix'].forEach((type) =>
['prefix', 'suffix'].forEach((type) =>
observe<TemplateRef<any>>(
this.field,
['props', type.toLowerCase()],
['props', type],
({ currentValue }) =>
currentValue &&
Promise.resolve().then(() => {
this.field.props![`_mat${type}`] = currentValue;
this.options.detectChanges!(this.field);
}),
),
Expand Down
8 changes: 4 additions & 4 deletions src/ui/material/form-field/src/form-field.wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ interface MatFormlyFieldProps extends FormlyFieldProps {
>
</mat-label>
<ng-container matPrefix *ngIf="props._matPrefix">
<ng-container [ngTemplateOutlet]="props._matPrefix" [ngTemplateOutletContext]="{ field: field }"></ng-container>
<ng-container matPrefix *ngIf="props.prefix">
<ng-container [ngTemplateOutlet]="props.prefix" [ngTemplateOutletContext]="{ field: field }"></ng-container>
</ng-container>
<ng-container matSuffix *ngIf="props._matSuffix">
<ng-container [ngTemplateOutlet]="props._matSuffix" [ngTemplateOutletContext]="{ field: field }"></ng-container>
<ng-container matSuffix *ngIf="props.suffix">
<ng-container [ngTemplateOutlet]="props.suffix" [ngTemplateOutletContext]="{ field: field }"></ng-container>
</ng-container>
<mat-error>
Expand Down

0 comments on commit 05891df

Please sign in to comment.