Skip to content

Commit 889482e

Browse files
committed
fix(tap): fire input behavior when tap/clicking file input label. Closes #1699
1 parent 39f6e3a commit 889482e

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

Diff for: js/utils/tap.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -228,12 +228,20 @@ ionic.tap = {
228228
},
229229

230230
requiresNativeClick: function(ele) {
231-
if(!ele || ele.disabled || (/^(file|range)$/i).test(ele.type) || (/^(object|video)$/i).test(ele.tagName) ) {
231+
if(!ele || ele.disabled || (/^(file|range)$/i).test(ele.type) || (/^(object|video)$/i).test(ele.tagName) || ionic.tap.isLabelContainingFileInput(ele) ) {
232232
return true;
233233
}
234234
return ionic.tap.isElementTapDisabled(ele);
235235
},
236236

237+
isLabelContainingFileInput: function(ele) {
238+
var lbl = tapContainingElement(ele);
239+
if(lbl.tagName !== 'LABEL') return false;
240+
var fileInput = lbl.querySelector('input[type=file]');
241+
if(fileInput && fileInput.disabled === false) return true;
242+
return false;
243+
},
244+
237245
isElementTapDisabled: function(ele) {
238246
if(ele && ele.nodeType === 1) {
239247
var element = ele;

Diff for: test/html/tapInputs.html

+9
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,15 @@
168168
<option>United States</option>
169169
</select>
170170
</div>
171+
<div class="item item-divider">
172+
File Input
173+
</div>
174+
<label class="item item-input">
175+
<div class="input-label">
176+
<i class="icon ion-document-text"></i> File
177+
</div>
178+
<input type="file"/>
179+
</label>
171180

172181
<div class="item item-divider">
173182
Other Tests

Diff for: test/unit/utils/tap.unit.js

+18
Original file line numberDiff line numberDiff line change
@@ -746,6 +746,24 @@ describe('Ionic Tap', function() {
746746
expect( ionic.tap.requiresNativeClick( div5 ) ).toEqual(true);
747747
});
748748

749+
it('Should ionic.tap.requiresNativeClick for labels containing input[file]', function() {
750+
var lbl = document.createElement('label');
751+
var ele = document.createElement('input');
752+
ele.type = 'file';
753+
lbl.appendChild(ele);
754+
expect( ionic.tap.requiresNativeClick( lbl ) ).toEqual(true);
755+
});
756+
757+
it('Should ionic.tap.requiresNativeClick for elements underneath labels containing input[file]', function() {
758+
var lbl = document.createElement('label');
759+
var txt = document.createElement('span');
760+
var ele = document.createElement('input');
761+
ele.type = 'file';
762+
lbl.appendChild(ele);
763+
lbl.appendChild(txt);
764+
expect( ionic.tap.requiresNativeClick( txt ) ).toEqual(true);
765+
});
766+
749767
it('Should not allow a click that has an textarea target but not created by tapClick', function() {
750768
var e = {
751769
target: document.createElement('textarea'),

0 commit comments

Comments
 (0)