Skip to content

Commit

Permalink
fix(tap): select tag not working in IE
Browse files Browse the repository at this point in the history
Cannot prevent default on mousedown in IE when the target is an option
or select element. Closes #1435
  • Loading branch information
Adam Bradley committed May 20, 2014
1 parent 7344614 commit 7059b81
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion js/utils/tap.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
25 changes: 25 additions & 0 deletions test/unit/utils/tap.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down

0 comments on commit 7059b81

Please sign in to comment.