Skip to content

Commit f9a576e

Browse files
brandyscarneyadamdbradley
authored andcommitted
fix(input): pass readonly from ion-input down to native input
also adds to placeholder test an input and textarea with readonly that can be toggled fixes #6408
1 parent 7a6ba2d commit f9a576e

File tree

3 files changed

+35
-5
lines changed

3 files changed

+35
-5
lines changed

src/components/input/input.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ import { Platform } from '../../platform/platform';
8080
@Component({
8181
selector: 'ion-input,ion-textarea',
8282
template:
83-
'<input [(ngModel)]="_value" [type]="type" (blur)="inputBlurred($event)" (focus)="inputFocused($event)" [placeholder]="placeholder" [disabled]="disabled" class="text-input" [ngClass]="\'text-input-\' + _mode" *ngIf="_type!==\'textarea\'" #input>' +
84-
'<textarea [(ngModel)]="_value" (blur)="inputBlurred($event)" (focus)="inputFocused($event)" [placeholder]="placeholder" [disabled]="disabled" class="text-input" [ngClass]="\'text-input-\' + _mode" *ngIf="_type===\'textarea\'" #textarea></textarea>' +
83+
'<input [(ngModel)]="_value" [type]="type" (blur)="inputBlurred($event)" (focus)="inputFocused($event)" [placeholder]="placeholder" [disabled]="disabled" [readonly]="readonly" class="text-input" [ngClass]="\'text-input-\' + _mode" *ngIf="_type!==\'textarea\'" #input>' +
84+
'<textarea [(ngModel)]="_value" (blur)="inputBlurred($event)" (focus)="inputFocused($event)" [placeholder]="placeholder" [disabled]="disabled" [readonly]="readonly" class="text-input" [ngClass]="\'text-input-\' + _mode" *ngIf="_type===\'textarea\'" #textarea></textarea>' +
8585
'<input [type]="type" aria-hidden="true" next-input *ngIf="_useAssist">' +
8686
'<button ion-button clear [hidden]="!clearInput" type="button" class="text-input-clear-icon" (click)="clearTextInput()" (mousedown)="clearTextInput()"></button>' +
8787
'<div (touchstart)="pointerStart($event)" (touchend)="pointerEnd($event)" (mousedown)="pointerStart($event)" (mouseup)="pointerEnd($event)" class="input-cover" tappable *ngIf="_useAssist"></div>',
@@ -96,6 +96,7 @@ export class TextInput extends Ion implements IonicFormInput {
9696
_coord: PointerCoordinates;
9797
_didBlurAfterEdit: boolean;
9898
_disabled: boolean = false;
99+
_readonly: boolean = false;
99100
_isTouch: boolean;
100101
_keyboardHeight: number;
101102
_native: NativeInput;
@@ -164,7 +165,7 @@ export class TextInput extends Ion implements IonicFormInput {
164165
@Input() placeholder: string = '';
165166

166167
/**
167-
* @input {bool} A clear icon will appear in the input when there is a value. Clicking it clears the input.
168+
* @input {boolean} A clear icon will appear in the input when there is a value. Clicking it clears the input.
168169
*/
169170
@Input()
170171
get clearInput() {
@@ -208,7 +209,7 @@ export class TextInput extends Ion implements IonicFormInput {
208209
}
209210

210211
/**
211-
* @input {bool} If the input should be disabled or not
212+
* @input {boolean} If the input should be disabled or not
212213
*/
213214
@Input()
214215
get disabled() {
@@ -226,6 +227,17 @@ export class TextInput extends Ion implements IonicFormInput {
226227
this._native && this._native.isDisabled(val);
227228
}
228229

230+
/**
231+
* @input {boolean} If the input should be readonly or not
232+
*/
233+
@Input()
234+
get readonly() {
235+
return this._readonly;
236+
}
237+
set readonly(val: boolean) {
238+
this._readonly = isTrueProperty(val);
239+
}
240+
229241
/**
230242
* @input {string} The mode to apply to this component.
231243
*/

src/components/input/test/placeholder-labels/app.module.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,14 @@ import { IonicApp, IonicModule } from '../../../../../ionic-angular';
55
@Component({
66
templateUrl: 'main.html'
77
})
8-
export class E2EPage {}
8+
export class E2EPage {
9+
isReadonly: boolean = true;
10+
11+
toggleReadonly() {
12+
this.isReadonly = !this.isReadonly;
13+
}
14+
15+
}
916

1017
@Component({
1118
template: '<ion-nav [root]="rootPage"></ion-nav>'

src/components/input/test/placeholder-labels/main.html

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
<ion-toolbar>
44
<ion-title>Placeholder Label Text Input</ion-title>
5+
<ion-buttons end>
6+
<button ion-button (click)="toggleReadonly()">Toggle</button>
7+
</ion-buttons>
58
</ion-toolbar>
69

710
</ion-header>
@@ -19,6 +22,10 @@
1922
<ion-input placeholder="Text Input Placeholder" value="Text Input Value"></ion-input>
2023
</ion-item>
2124

25+
<ion-item>
26+
<ion-input placeholder="Text Input Readonly" [readonly]="isReadonly" value="Text Input Readonly"></ion-input>
27+
</ion-item>
28+
2229
<ion-item>
2330
<ion-icon name="call" item-left></ion-icon>
2431
<ion-input placeholder="Text Input Placeholder"></ion-input>
@@ -37,6 +44,10 @@
3744
<ion-textarea placeholder="ion-textarea Placeholder" value="Textarea value"></ion-textarea>
3845
</ion-item>
3946

47+
<ion-item>
48+
<ion-textarea placeholder="ion-textarea Readonly" [readonly]="isReadonly" value="Textarea Readonly"></ion-textarea>
49+
</ion-item>
50+
4051
</ion-list>
4152

4253
<ion-list inset>

0 commit comments

Comments
 (0)