Skip to content

Commit

Permalink
fix(input): add/remove disabled on native text input
Browse files Browse the repository at this point in the history
Close #5280
  • Loading branch information
adamdbradley committed Feb 1, 2016
1 parent 3e8b7ca commit 11b8e08
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 0 deletions.
14 changes: 14 additions & 0 deletions ionic/components/input/input-base.ts
Expand Up @@ -6,6 +6,7 @@ import {Content} from '../content/content';
import {Form} from '../../util/form';
import {Item} from '../item/item';
import {IonicApp} from '../app/app';
import {isTrueProperty} from '../../util/util';
import {Label} from '../label/label';
import {pointerCoord, hasPointerMoved, closest} from '../../util/dom';
import {NavController} from '../nav/nav-controller';
Expand All @@ -16,6 +17,7 @@ import {Platform} from '../../platform/platform';
export class InputBase {
protected _coord;
protected _deregScroll;
protected _disabled: boolean = false;
protected _keyboardHeight;
protected _scrollMove: EventListener;
protected _type: string = 'text';
Expand Down Expand Up @@ -136,6 +138,17 @@ export class InputBase {
}
}

@Input()
get disabled() {
return this._disabled;
}

set disabled(val) {
this._disabled = isTrueProperty(val);
this._item && this._item.setCssClass('item-input-disabled', this._disabled);
this._native && this._native.isDisabled(this._disabled);
}

/**
* @private
*/
Expand All @@ -161,6 +174,7 @@ export class InputBase {
});

this.checkHasValue(nativeInput.getValue());
this.disabled = this._disabled;
}

/**
Expand Down
4 changes: 4 additions & 0 deletions ionic/components/input/input.scss
Expand Up @@ -38,6 +38,10 @@ textarea.text-input {
display: block;
}

.text-input[disabled] {
opacity: 0.4;
}


input.text-input:-webkit-autofill {
background-color: transparent;
Expand Down
4 changes: 4 additions & 0 deletions ionic/components/input/native-input.ts
Expand Up @@ -51,6 +51,10 @@ export class NativeInput {
this._renderer.setElementAttribute(this._elementRef.nativeElement, 'aria-labelledby', val);
}

isDisabled(val: boolean) {
this._renderer.setElementAttribute(this._elementRef.nativeElement, 'disabled', val ? '' : null);
}

/**
* @private
*/
Expand Down
4 changes: 4 additions & 0 deletions ionic/components/input/test/form-inputs/index.ts
Expand Up @@ -32,4 +32,8 @@ class E2EApp {
this.submitted = true;
}

disable() {
this.isTextAreaDisabled = !this.isTextAreaDisabled;
}

}
14 changes: 14 additions & 0 deletions ionic/components/input/test/form-inputs/main.html
Expand Up @@ -89,4 +89,18 @@

<ion-input placeholder="Stand-alone textarea"></ion-input>

<ion-list>
<ion-item>
<ion-label>Disabled Input</ion-label>
<ion-input disabled value="Value"></ion-input>
</ion-item>

<ion-item>
<ion-label>Disabled TextArea</ion-label>
<ion-textarea [disabled]="isTextAreaDisabled" value="Value"></ion-textarea>
</ion-item>
</ion-list>

<button (click)="disable()">Disable</button>

</ion-content>

0 comments on commit 11b8e08

Please sign in to comment.