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): pass readonly from ion-input down to native input #10120

Merged
merged 1 commit into from
Jan 23, 2017
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
20 changes: 16 additions & 4 deletions src/components/input/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ import { Platform } from '../../platform/platform';
@Component({
selector: 'ion-input,ion-textarea',
template:
'<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>' +
'<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>' +
'<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>' +
'<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>' +
'<input [type]="type" aria-hidden="true" next-input *ngIf="_useAssist">' +
'<button ion-button clear [hidden]="!clearInput" type="button" class="text-input-clear-icon" (click)="clearTextInput()" (mousedown)="clearTextInput()"></button>' +
'<div (touchstart)="pointerStart($event)" (touchend)="pointerEnd($event)" (mousedown)="pointerStart($event)" (mouseup)="pointerEnd($event)" class="input-cover" tappable *ngIf="_useAssist"></div>',
Expand All @@ -96,6 +96,7 @@ export class TextInput extends Ion implements IonicFormInput {
_coord: PointerCoordinates;
_didBlurAfterEdit: boolean;
_disabled: boolean = false;
_readonly: boolean = false;
_isTouch: boolean;
_keyboardHeight: number;
_native: NativeInput;
Expand Down Expand Up @@ -164,7 +165,7 @@ export class TextInput extends Ion implements IonicFormInput {
@Input() placeholder: string = '';

/**
* @input {bool} A clear icon will appear in the input when there is a value. Clicking it clears the input.
* @input {boolean} A clear icon will appear in the input when there is a value. Clicking it clears the input.
*/
@Input()
get clearInput() {
Expand Down Expand Up @@ -208,7 +209,7 @@ export class TextInput extends Ion implements IonicFormInput {
}

/**
* @input {bool} If the input should be disabled or not
* @input {boolean} If the input should be disabled or not
*/
@Input()
get disabled() {
Expand All @@ -226,6 +227,17 @@ export class TextInput extends Ion implements IonicFormInput {
this._native && this._native.isDisabled(val);
}

/**
* @input {boolean} If the input should be readonly or not
*/
@Input()
get readonly() {
return this._readonly;
}
set readonly(val: boolean) {
this._readonly = isTrueProperty(val);
}

/**
* @input {string} The mode to apply to this component.
*/
Expand Down
9 changes: 8 additions & 1 deletion src/components/input/test/placeholder-labels/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,14 @@ import { IonicApp, IonicModule } from '../../../../../ionic-angular';
@Component({
templateUrl: 'main.html'
})
export class E2EPage {}
export class E2EPage {
isReadonly: boolean = true;

toggleReadonly() {
this.isReadonly = !this.isReadonly;
}

}

@Component({
template: '<ion-nav [root]="rootPage"></ion-nav>'
Expand Down
11 changes: 11 additions & 0 deletions src/components/input/test/placeholder-labels/main.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

<ion-toolbar>
<ion-title>Placeholder Label Text Input</ion-title>
<ion-buttons end>
<button ion-button (click)="toggleReadonly()">Toggle</button>
</ion-buttons>
</ion-toolbar>

</ion-header>
Expand All @@ -19,6 +22,10 @@
<ion-input placeholder="Text Input Placeholder" value="Text Input Value"></ion-input>
</ion-item>

<ion-item>
<ion-input placeholder="Text Input Readonly" [readonly]="isReadonly" value="Text Input Readonly"></ion-input>
</ion-item>

<ion-item>
<ion-icon name="call" item-left></ion-icon>
<ion-input placeholder="Text Input Placeholder"></ion-input>
Expand All @@ -37,6 +44,10 @@
<ion-textarea placeholder="ion-textarea Placeholder" value="Textarea value"></ion-textarea>
</ion-item>

<ion-item>
<ion-textarea placeholder="ion-textarea Readonly" [readonly]="isReadonly" value="Textarea Readonly"></ion-textarea>
</ion-item>

</ion-list>

<ion-list inset>
Expand Down