Skip to content

Commit 5722900

Browse files
committed
fix(ionHeaderBar): do not tapScrollToTop for inputs
Fixes #1199
1 parent 46f8a87 commit 5722900

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

js/angular/directive/headerFooterBar.js

+10-2
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,16 @@ function tapScrollToTopDirective() {
8080
});
8181

8282
function onTap(e) {
83-
if (ionic.DomUtil.getParentOrSelfWithClass(e.target, 'button', 4)) {
84-
return;
83+
var depth = 3;
84+
var current = e.target;
85+
//Don't scroll to top in certain cases
86+
while (depth-- && current) {
87+
if (current.classList.contains('button') ||
88+
current.tagName.match(/input|textarea|select/i) ||
89+
current.isContentEditable) {
90+
return;
91+
}
92+
current = current.parentNode;
8593
}
8694
var touch = e.gesture && e.gesture.touches[0] || e.detail.touches[0];
8795
var bounds = $element[0].getBoundingClientRect();

test/unit/angular/directive/headerFooterBar.unit.js

+19-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,25 @@ describe('bar directives', function() {
2727
el.scope().$destroy();
2828
expect(ionic.off).toHaveBeenCalledWith('tap', callback, el[0]);
2929
});
30-
it('should ignore tap if it\'s in a button', function() {
30+
['input','textarea','select'].forEach(function(tag) {
31+
it('should ignore tap if it\'s in a ' + tag, function() {
32+
var el = setup();
33+
spyOn(ionic.DomUtil, 'rectContains');
34+
var child = angular.element('<' + tag + '>');
35+
el.append(child);
36+
ionic.trigger('tap', { target: child[0] }, true, true);
37+
expect(ionic.DomUtil.rectContains).not.toHaveBeenCalled();
38+
});
39+
});
40+
it('should ignore tap if it\'s in a [contenteditable]', function() {
41+
var el = setup();
42+
spyOn(ionic.DomUtil, 'rectContains');
43+
var child = angular.element('<div contenteditable>');
44+
el.append(child);
45+
ionic.trigger('tap', { target: child[0] }, true, true);
46+
expect(ionic.DomUtil.rectContains).not.toHaveBeenCalled();
47+
});
48+
it('should ignore tap if it\'s in a .button', function() {
3149
var el = setup();
3250
spyOn(ionic.DomUtil, 'rectContains');
3351
var child = angular.element('<div class="button">');

0 commit comments

Comments
 (0)