Autocomplete requires you to click twice in iOS after update to 1.11.0

前端 未结 12 1178
野趣味
野趣味 2020-12-01 02:41

Using jQuery 2.1.0 and jQuery.ui 1.11.0 Tested in iOS 7. iPhone and iPad Mini. Works on android and regular browsers.

The problem

We recently upgraded from

12条回答
  •  一整个雨季
    2020-12-01 03:04

    Solution from Raphaël Malié is almost perfect, but it needs evt.preventDefault() for touchend, otherwise it will generate a click on a link/button that is under clicked item.

        var movedWhildAutocomplete = false;
        $(document)
            .on('touchstart', '.ui-autocomplete li.ui-menu-item', function(){
                $(this).trigger('mouseenter');
                movedWhildAutocomplete = false;
            })
            .on('touchmove', '.ui-autocomplete li.ui-menu-item', function(){
                movedWhildAutocomplete = true;
            })
            .on('touchend', '.ui-autocomplete li.ui-menu-item', function(evt){
                if (!movedWhildAutocomplete) {
                    var $el = $(this);
                    if ($el.is(':visible') && $el.hasClass('ui-state-focus')) {
                        evt.preventDefault();
                        $el.trigger('click');
                    }
                }
                movedWhildAutocomplete = false;
            });
    

提交回复
热议问题