onIonInit update

This commit is contained in:
Adam Bradley
2015-07-17 09:41:19 -05:00
parent 7b372adc7c
commit 25960e0d52
5 changed files with 41 additions and 11 deletions

View File

@@ -108,11 +108,10 @@ export class IonInputItem extends Ion {
itemRegistry.push(this);
}
onInit() {
onIonInit() {
if (this.input && this.label) {
this.input.id = (this.input.id || 'input-' + this.id);
this.label.id = (this.label.id || 'label-' + this.id);
this.input.labelledBy = this.label.id;
this.label.labelFor = this.input.id;
}
}

View File

@@ -14,8 +14,6 @@ $input-label-color: #000 !default;
color: $input-label-color;
font-size: 1.6rem;
white-space: nowrap;
pointer-events: none;
}
.placeholder-icon {

View File

@@ -7,8 +7,12 @@ import {IonicConfig} from '../../config/config';
@Directive({
selector: 'label',
host: {
'[attr.id]': 'id',
'[attr.for]': 'labelFor',
'[class.input-label]': 'inputLabel'
'(touchstart)': 'pointerStart($event)',
'(touchend)': 'pointerEnd($event)',
'(mousedown)': 'pointerStart($event)',
'(mouseup)': 'pointerEnd($event)'
}
})
export class Label {
@@ -17,5 +21,35 @@ export class Label {
container.registerLabel(this);
this.inputLabel = true;
}
this.container = container;
this.scrollAssist = config.setting('keyboardScrollAssist');
}
pointerStart(ev) {
if (this.scrollAssist) {
// remember where the touchstart/mousedown started
this.startCoord = dom.pointerCoord(ev);
}
}
pointerEnd(ev) {
if (this.scrollAssist && this.container) {
// get where the touchend/mouseup ended
let endCoord = dom.pointerCoord(ev);
// focus this input if the pointer hasn't moved XX pixels
// and the input doesn't already have focus
console.log('!this.hasFocus()', !this.hasFocus());
if (!dom.hasPointerMoved(20, this.startCoord, endCoord)) {
ev.preventDefault();
ev.stopPropagation();
this.container.focus();
}
this.startCoord null;
}
}
}

View File

@@ -38,8 +38,7 @@ export class Input extends IonInputItem {
'(touchend)': 'pointerEnd($event)',
'(mousedown)': 'pointerStart($event)',
'(mouseup)': 'pointerEnd($event)',
'[attr.id]': 'id',
'[attr.aria-labelledby]': 'labelledBy'
'[attr.id]': 'id'
}
})
export class TextInput extends IonInput {
@@ -81,7 +80,7 @@ export class TextInput extends IonInput {
// and the input doesn't already have focus
console.log('!this.hasFocus()', !this.hasFocus());
if (this.startCoord && !dom.hasPointerMoved(20, this.startCoord, endCoord) && !this.hasFocus()) {
if (!dom.hasPointerMoved(20, this.startCoord, endCoord) && !this.hasFocus()) {
ev.preventDefault();
ev.stopPropagation();

View File

@@ -175,8 +175,8 @@ export function pointerCoord(ev) {
}
export function hasPointerMoved(tolerance, startCoord, endCoord) {
return Math.abs(startCoord.x - endCoord.x) > tolerance ||
Math.abs(startCoord.y - endCoord.y) > tolerance;
return startCoord && endCoord &&
(Math.abs(startCoord.x - endCoord.x) > tolerance || Math.abs(startCoord.y - endCoord.y) > tolerance);
}
export function hasFocus(ele) {