Skip to content

Commit

Permalink
fix(tap): get containing label of deeply nested element
Browse files Browse the repository at this point in the history
The `tapContainingElement` method was not working correctly to climb up
the DOM of a clicked element to potentially find an ancestor label
element. Closes #1643
  • Loading branch information
adamdbradley committed Jun 18, 2014
1 parent 3a3f7cf commit 2e3b854
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion js/utils/tap.js
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ function tapContainingElement(ele, allowSelf) {
for(var x=0; x<6; x++) {
if(!climbEle) break;
if(climbEle.tagName === 'LABEL') return climbEle;
climbEle = ele.parentElement;
climbEle = climbEle.parentElement;
}
if(allowSelf !== false) return ele;
}
Expand Down
24 changes: 24 additions & 0 deletions test/unit/utils/tap.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -940,6 +940,30 @@ describe('Ionic Tap', function() {
}
});

it('Should get containing element of label when passed a deeply nested div', function() {
var label = document.createElement('label');
var div1 = document.createElement('div');
var div2 = document.createElement('div');
var div3 = document.createElement('div');
var div4 = document.createElement('div');
var div5 = document.createElement('div');
var div6 = document.createElement('div');
div6.id = 'div6';

label.appendChild(div1);
div1.appendChild(div2);
div2.appendChild(div3);
div3.appendChild(div4);
div4.appendChild(div5);
div5.appendChild(div6);

// max depth
expect( tapContainingElement(div5).tagName ).toEqual('LABEL');

// too deep
expect( tapContainingElement(div6).id ).toEqual('div6');
});

it('Should get containing element of label when passed a label', function() {
var label = document.createElement('label');
expect( tapContainingElement(label).tagName ).toEqual('LABEL');
Expand Down

1 comment on commit 2e3b854

@adamdbradley
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could get the latest from the nightly build:
http://code.ionicframework.com/#nightly

Please sign in to comment.