Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fixed ontouched call #110

Merged
merged 3 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export class ComponentFile extends AngularGeneratedFile {
this.addImport(['ProxyInputs', 'ProxyMethods', 'ProxyOutputs'], utilsFile.relativePathFrom);
if (this.componentData.formData.length > 0) {
this.addImport('forwardRef', '@angular/core');
this.addImport(['Observable', 'fromEvent', 'merge'], 'rxjs');
this.addImport(['Observable', 'fromEvent', 'merge', 'first'], 'rxjs');
this.addImport('NG_VALUE_ACCESSOR', '@angular/forms');
this.addImport(genericCva.exports[0].specifiers[0].exported, genericCva.relativePathFrom);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,11 @@ export function CvaConstructor(componentFile: ComponentFile): string {
setDisabledState: (isDisabled: boolean): void => {
elementRef.nativeElement.disabled = isDisabled;
}
})`;
})
fromEvent(elementRef.nativeElement, 'focusout').pipe(
first()
).subscribe(() => this.onTouched());
`;
}
return '';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ export class GenericCva extends AngularGeneratedFile {
import { ControlValueAccessor } from '@angular/forms';
import {
BehaviorSubject,
distinctUntilChanged,
filter,
map,
Observable,
Expand All @@ -33,7 +32,6 @@ import {
takeUntil,
tap,
} from 'rxjs';
import fastDeepEqual from 'fast-deep-equal';

interface ValueProviderInterface<ValueType = any> {
value: ValueType;
Expand All @@ -47,15 +45,12 @@ export class GenericControlValueAccessor<ValueType = any>
{
onChange!: (val: ValueType) => void;
onTouched!: () => void;
private _value?: ValueType;
private _destroy$ = new Subject<void>();
private _onChangeSet$ = new BehaviorSubject(false);
constructor(protected host: ValueProviderInterface<ValueType>) {
this.host.valueUpdatedNotifier$
.pipe(
map(() => this.host.value),
distinctUntilChanged(fastDeepEqual),
tap((v) => (this._value = v)),
switchMap(this.onChange$),
takeUntil(this._destroy$)
)
Expand Down Expand Up @@ -86,7 +81,6 @@ export class GenericControlValueAccessor<ValueType = any>
}

writeValue(val: ValueType): void {
this._value = val;
this.host.value = val;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export class TsComponentFile extends AngularGeneratedFile {
if (this.componentData.formData.length > 0) {
this.addImport(['NG_VALUE_ACCESSOR'], '@angular/forms');
this.addImport(['forwardRef'], '@angular/core');
this.addImport(['merge', 'fromEvent'], 'rxjs');
this.addImport(['merge', 'fromEvent', 'first'], 'rxjs');
this.addImport(genericCva.exports[0].specifiers[0].exported, genericCva.relativePathFrom);
}
this.addImport({specifiers: [], path: this.componentData.path})
Expand Down Expand Up @@ -137,7 +137,11 @@ export class TsComponentFile extends AngularGeneratedFile {
setDisabledState: (isDisabled: boolean): void => {
elementRef.nativeElement.disabled = isDisabled;
}
})`;
})
fromEvent(elementRef.nativeElement, 'focusout').pipe(
first()
).subscribe(() => this.onTouched());
`;
}
return '';
}
Expand Down
Loading
Loading