Skip to content

Commit c77e159

Browse files
committed
Another solution for clicks triggered on underlying elements
1 parent 0d06066 commit c77e159

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

select2.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -735,11 +735,24 @@ the specific language governing permissions and limitations under the Apache Lic
735735
this.container.on("click", killEvent);
736736

737737
installFilteredMouseMove(this.results);
738-
this.dropdown.on("mousemove-filtered touchstart touchmove touchend", resultsSelector, this.bind(this.highlightUnderEvent));
739-
this.dropdown.on("touchend", resultsSelector, this.bind(this.selectHighlighted));
738+
739+
this.dropdown.on("mousemove-filtered", resultsSelector, this.bind(this.highlightUnderEvent));
740+
this.dropdown.on("touchstart touchmove touchend", resultsSelector, this.bind(function (event) {
741+
this._touchEvent = true;
742+
this.highlightUnderEvent(event);
743+
}));
740744
this.dropdown.on("touchmove", resultsSelector, this.bind(this.touchMoved));
741745
this.dropdown.on("touchstart touchend", resultsSelector, this.bind(this.clearTouchMoved));
742746

747+
// Waiting for a click event on touch devices to select option and hide dropdown
748+
// otherwise click will be triggered on an underlying element
749+
this.dropdown.on('click', this.bind(function (event) {
750+
if (this._touchEvent) {
751+
this._touchEvent = false;
752+
this.selectHighlighted();
753+
}
754+
}));
755+
743756
installDebouncedScroll(80, this.results);
744757
this.dropdown.on("scroll-debounced", resultsSelector, this.bind(this.loadMoreIfNeeded));
745758

0 commit comments

Comments
 (0)