Skip to content

Commit

Permalink
fix(core): avoid recursive focus/blur calls (#1936)
Browse files Browse the repository at this point in the history
fix #1935
  • Loading branch information
aitboudad committed Nov 17, 2019
1 parent 9ee889e commit 1ea96f9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 15 deletions.
10 changes: 2 additions & 8 deletions src/core/src/lib/components/formly.attributes.ts
Expand Up @@ -116,20 +116,14 @@ export class FormlyAttributes implements OnChanges, DoCheck, OnDestroy {
}

onFocus($event: any) {
if (!this.field.focus) {
this.field.focus = true;
}

this.field['___$focus'] = true;
if (this.to.focus) {
this.to.focus(this.field, $event);
}
}

onBlur($event: any) {
if (this.field.focus) {
this.field.focus = false;
}

this.field['___$focus'] = false;
if (this.to.blur) {
this.to.blur(this.field, $event);
}
Expand Down
14 changes: 7 additions & 7 deletions src/core/src/lib/utils.ts
Expand Up @@ -153,16 +153,16 @@ export function wrapProperty<T = any>(
prop: string,
setFn: (change: {currentValue: T, previousValue?: T, firstChange: boolean}) => void,
) {
let currentValue = field[prop];
setFn({ currentValue, firstChange: true });
defineHiddenProp(field, `___$${prop}`, field[prop]);
setFn({ currentValue: field[prop], firstChange: true });

Object.defineProperty(field, prop, {
configurable: true,
get: () => currentValue,
set: newVal => {
if (newVal !== currentValue) {
const previousValue = currentValue;
currentValue = newVal;
get: () => field[`___$${prop}`],
set: currentValue => {
if (currentValue !== field[`___$${prop}`]) {
const previousValue = field[`___$${prop}`];
field[`___$${prop}`] = currentValue;
setFn({ previousValue, currentValue, firstChange: false });
}
},
Expand Down

0 comments on commit 1ea96f9

Please sign in to comment.