fix(tap): get containing label of deeply nested element

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
This commit is contained in:
Adam Bradley
2014-06-18 15:03:52 -05:00
parent 3a3f7cf8ba
commit 2e3b854658
2 changed files with 25 additions and 1 deletions

View File

@@ -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;
}

View File

@@ -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');