add ion-input display type to inner label/input

This commit is contained in:
Adam Bradley
2015-12-08 14:59:50 -06:00
parent 21c8f35573
commit ad57fc02f8
2 changed files with 26 additions and 4 deletions

View File

@ -1,4 +1,4 @@
import {Directive, Optional} from 'angular2/angular2';
import {Directive, Optional, ElementRef, Renderer} from 'angular2/angular2';
import {Config} from '../../config/config';
import {TextInput} from './text-input';
@ -35,7 +35,12 @@ import {pointerCoord, hasPointerMoved} from '../../util/dom';
})
export class Label {
constructor(config: Config, @Optional() container: TextInput) {
constructor(
config: Config,
@Optional() container: TextInput,
private elementRef: ElementRef,
private renderer: Renderer
) {
this.scrollAssist = config.get('scrollAssist');
if (!this.id) {
this.id = 'lbl-' + (++labelIds);
@ -74,6 +79,10 @@ export class Label {
}
}
addClass(className) {
this.renderer.setElementClass(this.elementRef, className, true);
}
}
let labelIds = -1;

View File

@ -1,4 +1,4 @@
import {Component, Directive, NgIf, forwardRef, Host, Optional, ElementRef, Renderer, Attribute} from 'angular2/angular2';
import {Component, Directive, Attribute, NgIf, forwardRef, Host, Optional, ElementRef, Renderer, Attribute} from 'angular2/angular2';
import {NavController} from '../nav/nav-controller';
import {Config} from '../../config/config';
@ -73,7 +73,9 @@ export class TextInput {
app: IonicApp,
platform: Platform,
@Optional() @Host() scrollView: Content,
@Optional() navCtrl: NavController
@Optional() navCtrl: NavController,
@Attribute('floating-label') isFloating: string,
@Attribute('stacked-label') isStacked: string
) {
this.renderer = renderer;
@ -82,6 +84,7 @@ export class TextInput {
this.type = 'text';
this.lastTouch = 0;
this.displayType = (isFloating === '' ? 'floating' : (isStacked === '' ? 'stacked' : null));
this.app = app;
this.elementRef = elementRef;
@ -105,6 +108,9 @@ export class TextInput {
* @private
*/
registerInput(textInputElement) {
if (this.displayType) {
textInputElement.addClass(this.displayType + '-input');
}
this.input = textInputElement;
this.type = textInputElement.type || 'text';
}
@ -113,6 +119,9 @@ export class TextInput {
* @private
*/
registerLabel(label) {
if (this.displayType) {
label.addClass(this.displayType + '-label');
}
this.label = label;
}
@ -543,6 +552,10 @@ export class TextInputElement {
return dom.hasFocus(this.getNativeElement());
}
addClass(className) {
this.renderer.setElementClass(this.elementRef, className, true);
}
getNativeElement() {
return this.elementRef.nativeElement;
}