Skip to content

Commit 2752563

Browse files
committed
Merge pull request select2#2096 from springboardretail/mobile-fixes
make selection on iOS more intuitive
2 parents 63f342a + eb09dfc commit 2752563

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

select2.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,9 @@ the specific language governing permissions and limitations under the Apache Lic
736736

737737
installFilteredMouseMove(this.results);
738738
this.dropdown.on("mousemove-filtered touchstart touchmove touchend", resultsSelector, this.bind(this.highlightUnderEvent));
739+
this.dropdown.on("touchend", resultsSelector, this.bind(this.selectHighlighted));
740+
this.dropdown.on("touchmove", resultsSelector, this.bind(this.touchMoved));
741+
this.dropdown.on("touchstart touchend", resultsSelector, this.bind(this.clearTouchMoved));
739742

740743
installDebouncedScroll(80, this.results);
741744
this.dropdown.on("scroll-debounced", resultsSelector, this.bind(this.loadMoreIfNeeded));
@@ -1523,6 +1526,14 @@ the specific language governing permissions and limitations under the Apache Lic
15231526
this.results.find(".select2-highlighted").removeClass("select2-highlighted");
15241527
},
15251528

1529+
touchMoved: function() {
1530+
this._touchMoved = true;
1531+
},
1532+
1533+
clearTouchMoved: function() {
1534+
this._touchMoved = false;
1535+
},
1536+
15261537
// abstract
15271538
countSelectableResults: function() {
15281539
return this.findHighlightableChoices().length;
@@ -1761,6 +1772,10 @@ the specific language governing permissions and limitations under the Apache Lic
17611772

17621773
// abstract
17631774
selectHighlighted: function (options) {
1775+
if (this._touchMoved) {
1776+
this.clearTouchMoved();
1777+
return;
1778+
}
17641779
var index=this.highlight(),
17651780
highlighted=this.results.find(".select2-highlighted"),
17661781
data = highlighted.closest('.select2-result').data("select2-data");

0 commit comments

Comments
 (0)