Skip to content

Commit

Permalink
fix(ionHeaderBar): do not tapScrollToTop for inputs
Browse files Browse the repository at this point in the history
Fixes #1199
  • Loading branch information
ajoslin committed Apr 24, 2014
1 parent 46f8a87 commit 5722900
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
12 changes: 10 additions & 2 deletions js/angular/directive/headerFooterBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
20 changes: 19 additions & 1 deletion test/unit/angular/directive/headerFooterBar.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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('<div contenteditable>');
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('<div class="button">');
Expand Down

0 comments on commit 5722900

Please sign in to comment.