From 2e3b854658a5adf19321c433b28bdca95428d02d Mon Sep 17 00:00:00 2001 From: Adam Bradley Date: Wed, 18 Jun 2014 15:03:52 -0500 Subject: [PATCH] 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 --- js/utils/tap.js | 2 +- test/unit/utils/tap.unit.js | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/js/utils/tap.js b/js/utils/tap.js index c5903c8e83..907d9960c5 100644 --- a/js/utils/tap.js +++ b/js/utils/tap.js @@ -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; } diff --git a/test/unit/utils/tap.unit.js b/test/unit/utils/tap.unit.js index 4455ee78c4..b3969a096b 100644 --- a/test/unit/utils/tap.unit.js +++ b/test/unit/utils/tap.unit.js @@ -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');