Skip to content

Commit

Permalink
Adjusted open trigger to detect touch device and switch to click rath…
Browse files Browse the repository at this point in the history
…er than mousedown

Resolves issue where user cannot scroll past a full screen of select elements on iOS 7.
  • Loading branch information
Chris Crocker-White committed Jul 30, 2014
1 parent 67c79eb commit 0244d7a
Showing 1 changed file with 33 additions and 13 deletions.
46 changes: 33 additions & 13 deletions select2.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -2210,22 +2210,42 @@ the specific language governing permissions and limitations under the Apache Lic
this.selection.focus(); this.selection.focus();
})); }));


selection.on("mousedown touchstart", this.bind(function (e) { if(this.supportsTouchEvents)
// Prevent IE from generating a click event on the body {
reinsertElement(selection); selection.on("click", this.bind(function (e) {
// Prevent IE from generating a click event on the body
reinsertElement(selection);


if (!this.container.hasClass("select2-container-active")) { if (!this.container.hasClass("select2-container-active")) {
this.opts.element.trigger($.Event("select2-focus")); this.opts.element.trigger($.Event("select2-focus"));
} }


if (this.opened()) { if (this.opened()) {
this.close(); this.close();
} else if (this.isInterfaceEnabled()) { } else if (this.isInterfaceEnabled()) {
this.open(); this.open();
} }


killEvent(e); killEvent(e);
})); }));
} else {
selection.on("mousedown", this.bind(function (e) {
// Prevent IE from generating a click event on the body
reinsertElement(selection);

if (!this.container.hasClass("select2-container-active")) {
this.opts.element.trigger($.Event("select2-focus"));
}

if (this.opened()) {
this.close();
} else if (this.isInterfaceEnabled()) {
this.open();
}

killEvent(e);
}));
}


dropdown.on("mousedown touchstart", this.bind(function() { dropdown.on("mousedown touchstart", this.bind(function() {
if (this.opts.shouldFocusInput(this)) { if (this.opts.shouldFocusInput(this)) {
Expand Down

3 comments on commit 0244d7a

@adriand
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This patch worked for me. I think it should get merged in. Thanks @chrisys

@champsupertramp
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chrisys did they patch this into master? Thanks!

@steax85
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hi, apologies for bringing this up, the issue also shows up on chrome mobile, was this patch merged into master?

Please sign in to comment.