mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2026-03-13 10:22:08 +08:00
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:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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');
|
||||
|
||||
Reference in New Issue
Block a user