mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-19 03:32:21 +08:00
add ion-input display type to inner label/input
This commit is contained in:
@ -1,4 +1,4 @@
|
|||||||
import {Directive, Optional} from 'angular2/angular2';
|
import {Directive, Optional, ElementRef, Renderer} from 'angular2/angular2';
|
||||||
|
|
||||||
import {Config} from '../../config/config';
|
import {Config} from '../../config/config';
|
||||||
import {TextInput} from './text-input';
|
import {TextInput} from './text-input';
|
||||||
@ -35,7 +35,12 @@ import {pointerCoord, hasPointerMoved} from '../../util/dom';
|
|||||||
})
|
})
|
||||||
export class Label {
|
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');
|
this.scrollAssist = config.get('scrollAssist');
|
||||||
if (!this.id) {
|
if (!this.id) {
|
||||||
this.id = 'lbl-' + (++labelIds);
|
this.id = 'lbl-' + (++labelIds);
|
||||||
@ -74,6 +79,10 @@ export class Label {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
addClass(className) {
|
||||||
|
this.renderer.setElementClass(this.elementRef, className, true);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let labelIds = -1;
|
let labelIds = -1;
|
||||||
|
@ -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 {NavController} from '../nav/nav-controller';
|
||||||
import {Config} from '../../config/config';
|
import {Config} from '../../config/config';
|
||||||
@ -73,7 +73,9 @@ export class TextInput {
|
|||||||
app: IonicApp,
|
app: IonicApp,
|
||||||
platform: Platform,
|
platform: Platform,
|
||||||
@Optional() @Host() scrollView: Content,
|
@Optional() @Host() scrollView: Content,
|
||||||
@Optional() navCtrl: NavController
|
@Optional() navCtrl: NavController,
|
||||||
|
@Attribute('floating-label') isFloating: string,
|
||||||
|
@Attribute('stacked-label') isStacked: string
|
||||||
) {
|
) {
|
||||||
this.renderer = renderer;
|
this.renderer = renderer;
|
||||||
|
|
||||||
@ -82,6 +84,7 @@ export class TextInput {
|
|||||||
|
|
||||||
this.type = 'text';
|
this.type = 'text';
|
||||||
this.lastTouch = 0;
|
this.lastTouch = 0;
|
||||||
|
this.displayType = (isFloating === '' ? 'floating' : (isStacked === '' ? 'stacked' : null));
|
||||||
|
|
||||||
this.app = app;
|
this.app = app;
|
||||||
this.elementRef = elementRef;
|
this.elementRef = elementRef;
|
||||||
@ -105,6 +108,9 @@ export class TextInput {
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
registerInput(textInputElement) {
|
registerInput(textInputElement) {
|
||||||
|
if (this.displayType) {
|
||||||
|
textInputElement.addClass(this.displayType + '-input');
|
||||||
|
}
|
||||||
this.input = textInputElement;
|
this.input = textInputElement;
|
||||||
this.type = textInputElement.type || 'text';
|
this.type = textInputElement.type || 'text';
|
||||||
}
|
}
|
||||||
@ -113,6 +119,9 @@ export class TextInput {
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
registerLabel(label) {
|
registerLabel(label) {
|
||||||
|
if (this.displayType) {
|
||||||
|
label.addClass(this.displayType + '-label');
|
||||||
|
}
|
||||||
this.label = label;
|
this.label = label;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -543,6 +552,10 @@ export class TextInputElement {
|
|||||||
return dom.hasFocus(this.getNativeElement());
|
return dom.hasFocus(this.getNativeElement());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
addClass(className) {
|
||||||
|
this.renderer.setElementClass(this.elementRef, className, true);
|
||||||
|
}
|
||||||
|
|
||||||
getNativeElement() {
|
getNativeElement() {
|
||||||
return this.elementRef.nativeElement;
|
return this.elementRef.nativeElement;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user