mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-18 19:21:34 +08:00
TapInput extends IonInput
This commit is contained in:
@ -8,7 +8,7 @@ export * from 'ionic/components/icon/icon'
|
||||
export * from 'ionic/components/item/item'
|
||||
export * from 'ionic/components/item/item-group'
|
||||
export * from 'ionic/components/form/form'
|
||||
export * from 'ionic/components/form/input'
|
||||
export * from 'ionic/components/form/text-input'
|
||||
export * from 'ionic/components/form/label'
|
||||
export * from 'ionic/components/list/list'
|
||||
export * from 'ionic/components/modal/modal'
|
||||
|
@ -1,9 +1,11 @@
|
||||
import {Ion} from '../ion';
|
||||
import {IonicConfig} from '../../config/config';
|
||||
import * as dom from '../../util/dom';
|
||||
|
||||
let inputRegistry = [];
|
||||
let activeInput = null;
|
||||
let lastInput = null;
|
||||
let containerIds = -1;
|
||||
|
||||
|
||||
export class IonInput {
|
||||
@ -85,3 +87,33 @@ export class IonInput {
|
||||
|
||||
}
|
||||
|
||||
|
||||
export class IonInputContainer extends Ion {
|
||||
|
||||
constructor(
|
||||
elementRef: ElementRef,
|
||||
ionicConfig: IonicConfig
|
||||
) {
|
||||
super(elementRef, ionicConfig);
|
||||
this.id = ++containerIds;
|
||||
}
|
||||
|
||||
onInit() {
|
||||
if (this.input) {
|
||||
this.input.id = 'input-' + this.id;
|
||||
}
|
||||
if (this.label) {
|
||||
this.label.id = 'label-' + this.id;
|
||||
this.input.labelledBy = this.label.id;
|
||||
}
|
||||
}
|
||||
|
||||
registerInput(directive) {
|
||||
this.input = directive;
|
||||
}
|
||||
|
||||
registerLabel(directive) {
|
||||
this.label = directive;
|
||||
}
|
||||
|
||||
}
|
||||
|
28
ionic/components/form/tap-input.ts
Normal file
28
ionic/components/form/tap-input.ts
Normal file
@ -0,0 +1,28 @@
|
||||
import {Parent, Ancestor, Optional, ElementRef, Attribute} from 'angular2/angular2';
|
||||
|
||||
import {IonInput} from './form';
|
||||
import {IonicApp} from '../app/app';
|
||||
import {Content} from '../content/content';
|
||||
|
||||
|
||||
export class TapInput extends IonInput {
|
||||
constructor(
|
||||
@Optional() @Parent() container: Input,
|
||||
@Optional() @Ancestor() scrollView: Content,
|
||||
@Attribute('type') type: string,
|
||||
elementRef: ElementRef,
|
||||
app: IonicApp
|
||||
) {
|
||||
super(elementRef, app, scrollView);
|
||||
|
||||
if (container) {
|
||||
container.registerInput(this);
|
||||
this.container = container;
|
||||
}
|
||||
|
||||
this.type = type;
|
||||
this.elementRef = elementRef;
|
||||
this.tabIndex = this.tabIndex || '';
|
||||
}
|
||||
|
||||
}
|
@ -2,8 +2,7 @@ import {Directive, View, Parent, Ancestor, Optional, ElementRef, Attribute, forw
|
||||
|
||||
import {IonicDirective} from '../../config/annotations';
|
||||
import {IonicConfig} from '../../config/config';
|
||||
import {IonInput} from './form';
|
||||
import {Ion} from '../ion';
|
||||
import {IonInput, IonInputContainer} from './form';
|
||||
import {IonicApp} from '../app/app';
|
||||
import {Content} from '../content/content';
|
||||
import {ClickBlock} from '../../util/click-block';
|
||||
@ -14,32 +13,13 @@ import {Platform} from '../../platform/platform';
|
||||
@IonicDirective({
|
||||
selector: 'ion-input'
|
||||
})
|
||||
export class Input extends Ion {
|
||||
export class Input extends IonInputContainer {
|
||||
|
||||
constructor(
|
||||
elementRef: ElementRef,
|
||||
ionicConfig: IonicConfig
|
||||
) {
|
||||
super(elementRef, ionicConfig);
|
||||
this.id = ++inputIds;
|
||||
}
|
||||
|
||||
onInit() {
|
||||
if (this.input) {
|
||||
this.input.id = 'input-' + this.id;
|
||||
}
|
||||
if (this.label) {
|
||||
this.label.id = 'label-' + this.id;
|
||||
this.input.labelledBy = this.label.id;
|
||||
}
|
||||
}
|
||||
|
||||
registerInput(directive) {
|
||||
this.input = directive;
|
||||
}
|
||||
|
||||
registerLabel(directive) {
|
||||
this.label = directive;
|
||||
}
|
||||
|
||||
}
|
||||
@ -148,14 +128,12 @@ export class TextInput extends IonInput {
|
||||
}
|
||||
|
||||
receivedFocus(receivedFocus) {
|
||||
console.log('receivedFocus: ', receivedFocus)
|
||||
let self = this;
|
||||
let scrollView = self.scrollView;
|
||||
|
||||
self.isActiveInput(receivedFocus);
|
||||
|
||||
function touchMove(ev) {
|
||||
console.log('touchMove')
|
||||
if (!self.isPressHold()) {
|
||||
self.setFocusHolder(self.type);
|
||||
self.deregTouchMove();
|
||||
@ -177,27 +155,9 @@ export class TextInput extends IonInput {
|
||||
}
|
||||
|
||||
isPressHold() {
|
||||
console.log('pressStart:', this.pressStart, ' pressStart + 500 < now:', this.pressStart + 500 < Date.now())
|
||||
return this.pressStart && (this.pressStart + 500 < Date.now());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Directive({
|
||||
selector: 'label',
|
||||
host: {
|
||||
'[attr.id]': 'id'
|
||||
}
|
||||
})
|
||||
export class InputLabel {
|
||||
constructor(@Optional() @Parent() container: Input) {
|
||||
if (container) {
|
||||
container.registerLabel(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const SCROLL_INTO_VIEW_DURATION = 500;
|
||||
|
||||
let inputIds = -1;
|
@ -12,7 +12,7 @@ import {
|
||||
Toolbar,
|
||||
Icon,
|
||||
Checkbox, Switch,
|
||||
Input, TextInput, InputLabel,
|
||||
Input, TextInput, Label,
|
||||
Segment, SegmentButton, SegmentControlValueAccessor,
|
||||
RadioGroup, RadioButton, SearchBar,
|
||||
Nav, NavbarTemplate, Navbar, NavPush, NavPop,
|
||||
@ -61,7 +61,7 @@ export const IonicDirectives = [
|
||||
// Input
|
||||
forwardRef(() => Input),
|
||||
forwardRef(() => TextInput),
|
||||
forwardRef(() => InputLabel),
|
||||
forwardRef(() => Label),
|
||||
|
||||
// Nav
|
||||
forwardRef(() => Nav),
|
||||
|
Reference in New Issue
Block a user