question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Dropdown select does not work on iOS (safari)

See original GitHub issue

What you did: Tried dropdown example

What happened: I can open dropdown by clicking button, but I can’t select any other item

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:14 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
alfredringstadcommented, Jun 6, 2018

So I finally had some time to look into this. While I thought this was related to the original issue, I now realised that my problem might not be what @vonwao intended. If that is the case, I’m sorry for stealing this issue.

My problem exists when the toggle button is a <button> element. When I press the toggle button the first time, it opens the menu as it should. I can select other items in the list, or press anywhere else on the page to trigger the blur event and close the menu. However, if I instead press the toggle button again (so first toggle button to open, then toggle button to close), the menu stays open. This happens in Safari on iOS. I tried it out using the Xcode simulator on an iPhone 6 running iOS 9.

The problem seems to be that Safari on iOS triggers a blur event before the onClick event, if the button was manually focused. This causes, as I posted in a comment above, that the menu is first reset (isOpen = false) and then toggled (isOpen = true). I think the desired behaviour is that the menu should only be toggled (isOpen = false).

To fix this, I found a solution where we can store the blur event target and compare it to the active selection and see if it’s the same element that is focused again. In that case we shouldn’t trigger the blur action.

This code example would solve this problem:

  button_handleBlur = event => {
    const target = event.target; // Need to save this reference since it's not available on event when we're inside the setTimeout function
    // Need setTimeout, so that when the user presses Tab, the activeElement is the next focused element, not body element
    setTimeout(() => {
      if (
        !this.isMouseDown &&
        (this.props.environment.document.activeElement == null ||
          this.props.environment.document.activeElement.id !== this.inputId) &&
        this.props.environment.document.activeElement !== target // Make sure same element is not re-focused
      ) {
        this.reset({type: Downshift.stateChangeTypes.blurButton})
      }
    })
  }

Note that this is only a problem when the toggle button is a <button> element.

Another possible workaround (that could have some more side effects) is to use preventDownshiftDefault on the onBlur method:

<button
  {...getToggleButtonProps({
    onBlur: e => (e.preventDownshiftDefault = true) // Workaround for a Downshift bug in Safari on iOS where onBlur is wrongfully triggered before onClick
  })}
>
  Toggle button
</button>;

I’d happily create a pull request if you think my code example is a good solution for this.

1reaction
Drapegnikcommented, Aug 11, 2018

Sorry, it was my issue: I did not use getMenuProps and targetWithinDownshift(event.target, false) return false, so it was interpreted as outside click.

Read more comments on GitHub >

github_iconTop Results From Across the Web

In IOS 15 We have facing some dropdown issue
Clear the browser cache of Safari thru the settings. Using Safari, visit the page and add to Home Screen. Launch the Home Screen...
Read more >
Select Dropdown is not working on iPhone iOS version 14.6 in ...
I'm not sure why the drodown is not working on iPhone iOS 14.6 safari browser when with fastclick.js include.
Read more >
Dropdown select not working on mobile Safari (iOS) - Select2
I use select2 in a plugin on WordPress, and a user reported that the select2 dropdown has to be touched (clicked) twice in...
Read more >
Drop-down menu not working in Safari - Search & Filter Support
It may be, if the device is an Apple, that the dropbown boxes need making in to 'comboboxes' (there is an option in...
Read more >
Safari's dropdown menu not working on brand new iphone ...
Safari's dropdown menu not working on brand new iphone (tried updating ios but didn't work) ... Scroll to the name. Tap the name...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found