Skip to content

Commit eaf27bf

Browse files
committed
refactor(input-group): add input read only directive
Adds the ability to apply and override the read-only state of an input group via a CSS class.
1 parent 03219e5 commit eaf27bf

File tree

4 files changed

+43
-1
lines changed

4 files changed

+43
-1
lines changed

projects/igniteui-angular/src/lib/date-picker/date-picker.component.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
</igx-prefix>
1515
}
1616

17-
<input class="igx-date-picker__input-date" [displayValuePipe]="formatter ? displayValue : null" igxInput
17+
<input class="igx-date-picker__input-date"
18+
[igxReadOnlyInput]="readOnly"
19+
[displayValuePipe]="formatter ? displayValue : null" igxInput
1820
[igxDateTimeEditor]="inputFormat" [displayFormat]="displayFormat"
1921
[minValue]="minValue" [maxValue]="maxValue" [spinDelta]="spinDelta" [spinLoop]="spinLoop"
2022
[disabled]="disabled" [placeholder]="placeholder" [readonly]="!isDropdown || readOnly"

projects/igniteui-angular/src/lib/date-picker/date-picker.component.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ import { IgxTextSelectionDirective } from '../directives/text-selection/text-sel
6868
import { getCurrentResourceStrings } from '../core/i18n/resources';
6969
import { fadeIn, fadeOut } from 'igniteui-angular/animations';
7070
import { PickerCalendarOrientation } from '../date-common/types';
71+
import { IgxReadOnlyInputDirective } from '../directives/input/readOnlyInput.directive';
7172

7273
let NEXT_ID = 0;
7374

@@ -96,6 +97,7 @@ let NEXT_ID = 0;
9697
IgxPrefixDirective,
9798
IgxIconComponent,
9899
IgxInputDirective,
100+
IgxReadOnlyInputDirective,
99101
IgxDateTimeEditorDirective,
100102
IgxTextSelectionDirective,
101103
IgxSuffixDirective
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { Directive, effect, inject, input } from '@angular/core';
2+
import { IgxInputGroupComponent } from '../../input-group/input-group.component';
3+
4+
@Directive({
5+
selector: '[igxReadOnlyInput]',
6+
exportAs: 'igxReadOnlyInput',
7+
standalone: true
8+
})
9+
export class IgxReadOnlyInputDirective {
10+
public igxReadOnlyInput = input<boolean>(false);
11+
12+
private _inputGroup: IgxInputGroupComponent | null = inject(
13+
IgxInputGroupComponent,
14+
{
15+
optional: true
16+
}
17+
);
18+
19+
constructor() {
20+
effect(() => {
21+
if (this._inputGroup) {
22+
this._inputGroup.readOnly = this.igxReadOnlyInput();
23+
}
24+
});
25+
}
26+
}

projects/igniteui-angular/src/lib/input-group/input-group.component.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,18 @@ export class IgxInputGroupComponent implements IgxInputGroupBase, AfterContentCh
126126
private _filled = false;
127127
private _theme: IgxTheme;
128128
private _resourceStrings = getCurrentResourceStrings(InputResourceStringsEN);
129+
private _readOnly: undefined | boolean;
130+
131+
/** @hidden @internal */
132+
@HostBinding('class.igx-input-group--readonly')
133+
public get readOnly(): boolean {
134+
return this._readOnly ?? (this.input?.nativeElement.readOnly || false);
135+
}
136+
137+
/** @hidden @internal */
138+
public set readOnly(value: boolean) {
139+
this._readOnly = value;
140+
}
129141

130142
/** @hidden */
131143
@HostBinding('class.igx-input-group--valid')

0 commit comments

Comments
 (0)