From c25e04d6b09356a3ef557f41bc3f4bedebf0eb32 Mon Sep 17 00:00:00 2001 From: Andy Joslin Date: Thu, 24 Apr 2014 07:29:16 -0600 Subject: [PATCH] fix(ionHeaderBar): do not tapScrollToTop for inputs Fixes #1199 --- js/angular/directive/headerFooterBar.js | 12 +++++++++-- .../angular/directive/headerFooterBar.unit.js | 20 ++++++++++++++++++- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/js/angular/directive/headerFooterBar.js b/js/angular/directive/headerFooterBar.js index b2e1b1b3df7..d93b517a64e 100644 --- a/js/angular/directive/headerFooterBar.js +++ b/js/angular/directive/headerFooterBar.js @@ -80,8 +80,16 @@ function tapScrollToTopDirective() { }); function onTap(e) { - if (ionic.DomUtil.getParentOrSelfWithClass(e.target, 'button', 4)) { - return; + var depth = 3; + var current = e.target; + //Don't scroll to top in certain cases + while (depth-- && current) { + if (current.classList.contains('button') || + current.tagName.match(/input|textarea|select/i) || + current.isContentEditable) { + return; + } + current = current.parentNode; } var touch = e.gesture && e.gesture.touches[0] || e.detail.touches[0]; var bounds = $element[0].getBoundingClientRect(); diff --git a/test/unit/angular/directive/headerFooterBar.unit.js b/test/unit/angular/directive/headerFooterBar.unit.js index 07296bd27b8..1c4aec20528 100644 --- a/test/unit/angular/directive/headerFooterBar.unit.js +++ b/test/unit/angular/directive/headerFooterBar.unit.js @@ -27,7 +27,25 @@ describe('bar directives', function() { el.scope().$destroy(); expect(ionic.off).toHaveBeenCalledWith('tap', callback, el[0]); }); - it('should ignore tap if it\'s in a button', function() { + ['input','textarea','select'].forEach(function(tag) { + it('should ignore tap if it\'s in a ' + tag, function() { + var el = setup(); + spyOn(ionic.DomUtil, 'rectContains'); + var child = angular.element('<' + tag + '>'); + el.append(child); + ionic.trigger('tap', { target: child[0] }, true, true); + expect(ionic.DomUtil.rectContains).not.toHaveBeenCalled(); + }); + }); + it('should ignore tap if it\'s in a [contenteditable]', function() { + var el = setup(); + spyOn(ionic.DomUtil, 'rectContains'); + var child = angular.element('
'); + el.append(child); + ionic.trigger('tap', { target: child[0] }, true, true); + expect(ionic.DomUtil.rectContains).not.toHaveBeenCalled(); + }); + it('should ignore tap if it\'s in a .button', function() { var el = setup(); spyOn(ionic.DomUtil, 'rectContains'); var child = angular.element('
');