From 7059b818ce1866a647b124440758fce601cf1cbe Mon Sep 17 00:00:00 2001 From: Adam Bradley Date: Tue, 20 May 2014 09:13:16 -0500 Subject: [PATCH] fix(tap): select tag not working in IE Cannot prevent default on mousedown in IE when the target is an option or select element. Closes #1435 --- js/utils/tap.js | 2 +- test/unit/utils/tap.unit.js | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/js/utils/tap.js b/js/utils/tap.js index bac6ccf00fc..8cf1cc09184 100644 --- a/js/utils/tap.js +++ b/js/utils/tap.js @@ -303,7 +303,7 @@ function tapMouseDown(e) { console.log('mousedown', 'stop event'); e.stopPropagation(); - if( !ionic.tap.isTextInput(e.target) || tapLastTouchTarget !== e.target ) { + if( (!ionic.tap.isTextInput(e.target) || tapLastTouchTarget !== e.target) && !(/^(select|option)$/i).test(e.target.tagName) ) { // If you preventDefault on a text input then you cannot move its text caret/cursor. // Allow through only the text input default. However, without preventDefault on an // input the 300ms delay can change focus on inputs after the keyboard shows up. diff --git a/test/unit/utils/tap.unit.js b/test/unit/utils/tap.unit.js index e4841a6399e..338516dfbcd 100644 --- a/test/unit/utils/tap.unit.js +++ b/test/unit/utils/tap.unit.js @@ -512,6 +512,31 @@ describe('Ionic Tap', function() { expect( mouseDownEvent.defaultedPrevented ).toEqual(true); }); + it('Should not preventDefault on mousedown if the target is a select element', function() { + tapEnabledTouchEvents = true; + var e = { + isTapHandled: false, + isIonicTap: false, + target: document.createElement('select'), + preventDefault: function(){ this.defaultedPrevented = true; }, + stopPropagation: function(){ this.stoppedPropagation = true; } + }; + tapMouseDown(e); + expect( e.stoppedPropagation ).toEqual(true); + expect( e.defaultedPrevented ).toBeUndefined(); + + e = { + isTapHandled: false, + isIonicTap: false, + target: document.createElement('option'), + preventDefault: function(){ this.defaultedPrevented = true; }, + stopPropagation: function(){ this.stoppedPropagation = true; } + }; + tapMouseDown(e); + expect( e.stoppedPropagation ).toEqual(true); + expect( e.defaultedPrevented ).toBeUndefined(); + }); + it('Should tapClick with touchend and fire immediately', function() { var e = { target: {