mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2026-03-13 10:22:08 +08:00
created containsOrIsTextInput
This commit is contained in:
@@ -95,13 +95,17 @@ ionic.tap = {
|
||||
(ele.tagName == 'INPUT' && !(/radio|checkbox|range|file|submit|reset/i).test(ele.type)));
|
||||
},
|
||||
|
||||
isLabelWithInput: function(ele) {
|
||||
isLabelWithTextInput: function(ele) {
|
||||
var container = tapContainingElement(ele, false);
|
||||
|
||||
return container &&
|
||||
return !!container &&
|
||||
ionic.tap.isTextInput( tapTargetElement( container ) );
|
||||
},
|
||||
|
||||
containsOrIsTextInput: function(ele) {
|
||||
return ionic.tap.isTextInput(ele) || ionic.tap.isLabelWithTextInput(ele);
|
||||
},
|
||||
|
||||
cloneFocusedInput: function(container, instance) {
|
||||
if(ionic.tap.hasCheckedClone) return;
|
||||
ionic.tap.hasCheckedClone = true;
|
||||
@@ -183,7 +187,7 @@ function tapClickGateKeeper(e) {
|
||||
console.debug('clickPrevent', e.target.tagName);
|
||||
e.stopPropagation();
|
||||
|
||||
if( !ionic.tap.isLabelWithInput(e.target) ) {
|
||||
if( !ionic.tap.isLabelWithTextInput(e.target) ) {
|
||||
// labels clicks from native should not preventDefault othersize keyboard will not show on input focus
|
||||
e.preventDefault();
|
||||
}
|
||||
@@ -311,7 +315,7 @@ function tapIgnoreEvent(e) {
|
||||
if(e.isTapHandled) return true;
|
||||
e.isTapHandled = true;
|
||||
|
||||
if( ionic.scroll.isScrolling ) {
|
||||
if( ionic.scroll.isScrolling && ionic.tap.containsOrIsTextInput(e.target) ) {
|
||||
e.preventDefault();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -686,7 +686,7 @@ ionic.views.Scroll = ionic.views.View.inherit({
|
||||
return;
|
||||
}
|
||||
|
||||
if( ionic.tap.isTextInput(e.target) || ionic.tap.isLabelWithInput(e.target) ) {
|
||||
if( ionic.tap.containsOrIsTextInput(e.target) ) {
|
||||
// do not start if the target is a text input
|
||||
// if there is a touchmove on this input, then we can start the scroll
|
||||
self.__hasStarted = false;
|
||||
@@ -705,7 +705,7 @@ ionic.views.Scroll = ionic.views.View.inherit({
|
||||
return;
|
||||
}
|
||||
|
||||
if( !self.__hasStarted && ( (ionic.tap.isTextInput(e.target) || ionic.tap.isLabelWithInput(e.target)) ) ) {
|
||||
if( !self.__hasStarted && ionic.tap.containsOrIsTextInput(e.target) ) {
|
||||
// the target is a text input and scroll has started
|
||||
// since the text input doesn't start on touchStart, do it here
|
||||
self.__hasStarted = true;
|
||||
|
||||
@@ -928,6 +928,40 @@ describe('Ionic Tap', function() {
|
||||
expect( ionic.tap.isTextInput(ele) ).toEqual(false);
|
||||
});
|
||||
|
||||
it('Should isLabelWithTextInput', function() {
|
||||
var label = document.createElement('label');
|
||||
expect( ionic.tap.isLabelWithTextInput(label) ).toEqual(false);
|
||||
|
||||
var span = document.createElement('span');
|
||||
expect( ionic.tap.isLabelWithTextInput(span) ).toEqual(false);
|
||||
|
||||
label.appendChild(span);
|
||||
expect( ionic.tap.isLabelWithTextInput(span) ).toEqual(false);
|
||||
|
||||
var textarea = document.createElement('textarea');
|
||||
expect( ionic.tap.isLabelWithTextInput(textarea) ).toEqual(false);
|
||||
|
||||
label.appendChild(textarea);
|
||||
expect( ionic.tap.isLabelWithTextInput(textarea) ).toEqual(true);
|
||||
});
|
||||
|
||||
it('Should containsOrIsTextInput', function() {
|
||||
var label = document.createElement('label');
|
||||
expect( ionic.tap.containsOrIsTextInput(label) ).toEqual(false);
|
||||
|
||||
var span = document.createElement('span');
|
||||
expect( ionic.tap.containsOrIsTextInput(span) ).toEqual(false);
|
||||
|
||||
label.appendChild(span);
|
||||
expect( ionic.tap.containsOrIsTextInput(span) ).toEqual(false);
|
||||
|
||||
var textarea = document.createElement('textarea');
|
||||
expect( ionic.tap.containsOrIsTextInput(textarea) ).toEqual(true);
|
||||
|
||||
label.appendChild(textarea);
|
||||
expect( ionic.tap.containsOrIsTextInput(textarea) ).toEqual(true);
|
||||
});
|
||||
|
||||
it('Should reset focus to tapTouchFocusedInput if the active element changed from mousedown', function() {
|
||||
tapEnabledTouchEvents = true;
|
||||
tapActiveElement(document.createElement('textarea'));
|
||||
@@ -960,8 +994,10 @@ describe('Ionic Tap', function() {
|
||||
expect( tapIgnoreEvent(e) ).toEqual(true);
|
||||
});
|
||||
|
||||
it('Should tapIgnoreEvent true because ionic.scroll.isScrolling', function(){
|
||||
it('Should tapIgnoreEvent true because ionic.scroll.isScrolling and target is a text input', function(){
|
||||
var target = document.createElement('textarea');
|
||||
var e = {
|
||||
target: target,
|
||||
preventDefault: function(){ this.preventedDefault=true; }
|
||||
};
|
||||
ionic.scroll.isScrolling = true;
|
||||
@@ -969,4 +1005,48 @@ describe('Ionic Tap', function() {
|
||||
expect( e.preventedDefault ).toEqual(true);
|
||||
});
|
||||
|
||||
it('Should tapIgnoreEvent true because ionic.scroll.isScrolling and target is span in a label containing a text input', function(){
|
||||
var label = document.createElement('label');
|
||||
var span = document.createElement('span');
|
||||
var textarea = document.createElement('textarea');
|
||||
|
||||
label.appendChild(span);
|
||||
label.appendChild(textarea);
|
||||
|
||||
var e = {
|
||||
target: label,
|
||||
preventDefault: function(){ this.preventedDefault=true; }
|
||||
};
|
||||
ionic.scroll.isScrolling = true;
|
||||
expect( tapIgnoreEvent(e) ).toEqual(true);
|
||||
expect( e.preventedDefault ).toEqual(true);
|
||||
});
|
||||
|
||||
it('Should tapIgnoreEvent false because ionic.scroll.isScrolling but target is not a text input', function(){
|
||||
var target = document.createElement('span');
|
||||
var e = {
|
||||
target: target,
|
||||
preventDefault: function(){ this.preventedDefault=true; }
|
||||
};
|
||||
ionic.scroll.isScrolling = true;
|
||||
expect( tapIgnoreEvent(e) ).toBeUndefined();
|
||||
});
|
||||
|
||||
it('Should tapIgnoreEvent false because ionic.scroll.isScrolling but target is a input[checkbox]', function(){
|
||||
var label = document.createElement('label');
|
||||
var span = document.createElement('span');
|
||||
var checkbox = document.createElement('input');
|
||||
checkbox.type = 'checkbox';
|
||||
|
||||
label.appendChild(span);
|
||||
label.appendChild(checkbox);
|
||||
|
||||
var e = {
|
||||
target: span,
|
||||
preventDefault: function(){ this.preventedDefault=true; }
|
||||
};
|
||||
ionic.scroll.isScrolling = true;
|
||||
expect( tapIgnoreEvent(e) ).toBeUndefined();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user