Skip to content

Commit

Permalink
fix(input): disable not working when working with formcontrol
Browse files Browse the repository at this point in the history
  • Loading branch information
adisreyaj committed Nov 10, 2023
1 parent 1dc53b9 commit 3479f4d
Showing 1 changed file with 11 additions and 7 deletions.
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 @@ import { InputAppearance } from './input-appearance';
[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 @@ export class InputComponent<T extends string | number> implements ControlValueAc
public value?: T;

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

@Input()
public appearance: InputAppearance = InputAppearance.Underline;
Expand All @@ -56,7 +56,9 @@ export class InputComponent<T extends string | number> implements ControlValueAc
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 @@ export class InputComponent<T extends string | number> implements ControlValueAc

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 @@ export class InputComponent<T extends string | number> implements ControlValueAc
}

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 @@ export class InputComponent<T extends string | number> implements ControlValueAc
}

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

0 comments on commit 3479f4d

Please sign in to comment.