Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Radix Select with Combobox instantly closes on Android #3274

Open
thgh opened this issue Dec 28, 2023 · 7 comments
Open

Radix Select with Combobox instantly closes on Android #3274

thgh opened this issue Dec 28, 2023 · 7 comments

Comments

@thgh
Copy link

thgh commented Dec 28, 2023

Current behavior

On press, options appear and disappear.

Steps to reproduce the bug

  1. Open https://ariakit.org/examples/combobox-radix-select on mobile
  2. Press the combobox

Expected behavior

It should show options, with keyboard focused on search field

Workaround

#3274 (comment)

Possible solutions

#3274 (comment)

@diegohaz
Copy link
Member

@thgh, could you please tell me which device and OS you're using?

@thgh
Copy link
Author

thgh commented Dec 28, 2023

Chrome on Android

@diegohaz
Copy link
Member

Alright, it could be an issue with Android, as I wasn't able to reproduce it on iOS.

@diegohaz diegohaz changed the title Radix select with Combobox instantly closes on mobile Radix Select with Combobox instantly closes on Android Dec 28, 2023
@georgekaran
Copy link
Contributor

georgekaran commented Jan 4, 2024

I debugged for a bit and found out that the resize event is triggered when the on-screen keyboard is displayed.
https://github.com/radix-ui/primitives/blob/f873591ac32c31df9e860d3b6fc65be3cb910ba4/packages/react/select/src/Select.tsx#L601-L609

React.useEffect(() => {
  const close = () => onOpenChange(false);
  window.addEventListener('blur', close);
  window.addEventListener('resize', close);
  return () => {
    window.removeEventListener('blur', close);
    window.removeEventListener('resize', close);
  };
}, [onOpenChange]);

@diegohaz
Copy link
Member

Issue on Radix UI: radix-ui/primitives#2634 (thanks @georgekaran)

The fix probably won't be merged soon, so it'd be great if we could figure out a way to fix it directly in the example.

@gorechavka
Copy link

has anyone found any workarounds?

@diegohaz
Copy link
Member

diegohaz commented Mar 13, 2024

This needs to be tested to ensure there are no unexpected side effects. But adding something like this to the component should work around the Radix issue:

useEffect(() => {
  const onResize = (event: Event) => {
    event.stopImmediatePropagation();
  }
  window.addEventListener("resize", onResize);
  return () => {
    window.removeEventListener("resize", onResize);
  }
}, []);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants