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

Android: Firefox and Chrome TextInput onSelectionChange events differ #2422

Open
1 task done
AndreasBBS opened this issue Nov 6, 2022 · 5 comments
Open
1 task done
Labels
bug: browser Bug associated with browsers

Comments

@AndreasBBS
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Describe the issue

Using a TextInput in Firefox on Android, when the cursor is dragged, the onSelectionChange is not triggered with the new selection values.

Chrome/Brave:

Record_2022-11-06-19-10-32.mp4

Firefox:

Record_2022-11-06-19-12-04.mp4

Expected behavior

I expect Firefox to behave the same as Chrome

Steps to reproduce

NPM versions:
react: 17.0.*
react-dom: 17.0.*
react-native-web: 0.18.*

Browser:
Firefox for Android

  1. Access an App using a TextInput
  2. Write some text in the text input
  3. Drag the cursor to a different position within the test
  4. Observe that the onSelectionEvent is not triggered as the cursor is being dragged

The codebox example I'm attaching makes it really easy to test this phenomenom

Test case

https://codesandbox.io/s/icy-pine-5tbtxj

Additional comments

No response

@necolas
Copy link
Owner

necolas commented Nov 6, 2022

This seems to be a Firefox Android bug based on what is said here Expensify/App#12298

@necolas necolas added bug: browser Bug associated with browsers and removed bug labels Nov 6, 2022
@AndreasBBS
Copy link
Author

@necolas I found this out: Expensify/App#12298 (comment)

It looks to me that the Firefox engine does approach this selection issue but in a different way than the Chrome engine. How does this library normalize across different engines behaviors?

@AndreasBBS
Copy link
Author

The onSelectionChange in the TextInput component is listening to the event 'selectionchange' on Document.

Firefox is the only browser that seems to implement correctly the behavior where the 'selectionchange' event is triggered on the input element.

There is already a bug opened on chrome for this: https://bugs.chromium.org/p/chromium/issues/detail?id=1327098

You can also see here that the list of browsers with compatibility for this feature is currently only Firefox but as more browsers adopt it this bug will only become more common.

@AndreasBBS
Copy link
Author

@necolas I've been digging deeper on this bug and I found out that this extends to React. I took a look at this package code and found out that onSelectionChange handler is simply passed to the input's onSelect which is handled by React. I tested this behavior with React's onSelect and figured out it also happens there. I opened this issue in case you're interested in following this. I think nothing needs to be changed in this lib, it does the right thing, it's React that needs to handle the onSelect situation better. I'm closing this issue. Sorry for wasting your time, I should have investigated this better before opening this.

@necolas
Copy link
Owner

necolas commented Nov 7, 2022

Thanks for all the investigation. I'd like to keep this open because we could still implement a fix using native event listeners instead of React DOM's event disturb

@necolas necolas reopened this Nov 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug: browser Bug associated with browsers
Projects
None yet
Development

No branches or pull requests

2 participants