Materialize select and dropdown: Touch event selecting wrong item

前端 未结 3 650
小鲜肉
小鲜肉 2021-01-07 09:02

This bug occurs not just in my code, but also on the Materialize documentation site, so I will use their code as an example:

相关标签:
3条回答
  • 2021-01-07 09:19

    After hours of trying, I found the answer: Stop propagation on touchend event, specifically

      $('li[id^="select-options"]').on('touchend', function (e) {
         e.stopPropagation();
      }); 
    

    Thanks for your attention and have a nice day.

    0 讨论(0)
  • 2021-01-07 09:19

    You should add the "browser-default" class to the select elements.

    Of course this will loose the usual materializecss look and feed on that select element Also on other devices.

    A possible workaround would be to add that class selectively only when the user browser is safari.

    0 讨论(0)
  • 2021-01-07 09:31

    Yes, JRSeabird, it works but It only solved the problem on DOMContentLoaded. If you want it to capture every event, try this

    $(document).click(function(){
        $('li[id^="select-options"]').on('touchend', function (e) {
            e.stopPropagation();
        });
    });
    
    0 讨论(0)
提交回复
热议问题