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(input): disable not working when working with formcontrol #2507

Merged
merged 2 commits into from
Nov 15, 2023
Merged
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
18 changes: 11 additions & 7 deletions projects/components/src/input/input.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
[min]="this.min"
[max]="this.max"
[required]="this.required"
[disabled]="this.disabled"
[disabled]="this.isDisabled"
[placeholder]="this.placeholderValue"
[attr.aria-label]="this.ariaLabel || 'input'"
[ngModel]="this.value"
Expand All @@ -47,7 +47,7 @@
public value?: T;

@Input()
public type?: string;
public type: string = 'text';

@Input()
public appearance: InputAppearance = InputAppearance.Underline;
Expand All @@ -56,7 +56,9 @@
public required: boolean = false;

@Input()
public disabled: boolean = false;
public set disabled(disabled: boolean) {
this.isDisabled = disabled;
}

@Input()
public min?: number | undefined;
Expand All @@ -74,6 +76,8 @@

public placeholderValue: string = '';

protected isDisabled: boolean = false;

public constructor(private readonly cdr: ChangeDetectorRef) {}

public ngOnChanges(changes: TypedSimpleChanges<this>): void {
Expand All @@ -93,12 +97,11 @@
}

public getStyleClasses(): string[] {
return [this.appearance, this.disabled ? 'disabled' : ''];
return [this.appearance, this.isDisabled ? 'disabled' : ''];
}

public writeValue(value?: string): void {
const coercedValue = this.coerceValueIfNeeded(value);
this.value = coercedValue;
this.value = this.coerceValueIfNeeded(value);

Check warning on line 104 in projects/components/src/input/input.component.ts

View check run for this annotation

Codecov / codecov/patch

projects/components/src/input/input.component.ts#L104

Added line #L104 was not covered by tests
this.cdr.markForCheck();
}

Expand All @@ -111,7 +114,8 @@
}

public setDisabledState(isDisabled?: boolean): void {
this.disabled = isDisabled ?? false;
this.isDisabled = isDisabled ?? false;
this.cdr.markForCheck();

Check warning on line 118 in projects/components/src/input/input.component.ts

View check run for this annotation

Codecov / codecov/patch

projects/components/src/input/input.component.ts#L118

Added line #L118 was not covered by tests
}

private coerceValueIfNeeded(value?: string): T | undefined {
Expand Down