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

PointerEvents="none" not working as expected on text elements #1741

Closed
RichardLindhout opened this issue Sep 17, 2020 · 4 comments
Closed

PointerEvents="none" not working as expected on text elements #1741

RichardLindhout opened this issue Sep 17, 2020 · 4 comments

Comments

@RichardLindhout
Copy link
Contributor

RichardLindhout commented Sep 17, 2020

The problem
ezgif-7-69f064634e14

I'm building a time picker component for React Native Paper with the PanResponder (which works great on the web!)
But I would expect the pointerEvents="none" to prevent the children from selecting text. But it does not. On iOS and Android text selection does not work in views with pointerEvents="none" even when the selectable={true} is used on

How to reproduce

Simplified test case: https://codesandbox.io/s/bold-shape-efdkb?file=/src/App.js

Steps to reproduce:

  1. Click twice on the button
  2. Text get selected while on Android/iOS it won't be selectable (even with selectable={true} on the Text

Expected behavior

I think we should add userSelect: 'none' (https://developer.mozilla.org/en-US/docs/Web/CSS/user-select) to the css when pointerEvents="none" is used. This way text inside buttons won't be selected if they have the pointerEvents disabled

Environment (include versions). Did this work in previous versions?

  • React Native for Web (version): 0.13.8
  • React Native: 0.63.2
  • React (version): 16.13.1
  • Browser: Google Chrome

Additional context

const pointerEventsStyles = StyleSheet.create({

https://github.com/necolas/react-native-web/blob/master/packages/react-native-web/src/exports/StyleSheet/compile.js#L150

@RichardLindhout
Copy link
Contributor Author

I just forgot about selectable={false} on elements which is implemented already! However it would still be nice to have the same behaviour on the web but less important as I first thought :)

@necolas
Copy link
Owner

necolas commented Sep 17, 2020

That's right, you can disable text selection as needed. I think React Native gets text selection wrong by default and produces inaccessible experiences, especially on web. It looks like it also has a different relationship between pointerEvents and text selection behavior, and the fact that you cannot select text within a tree that has no pointer events looks to me like a bug in React Native. So I don't think it's worth changing RNWeb

One thing we should do though, is make it so that this works:

<Text selectable={false}>Some <Text selectable={true}>text</Text></Text>

@RichardLindhout
Copy link
Contributor Author

RichardLindhout commented Sep 17, 2020

I agree this is more or less a bug in React Native!

-> on the nested text

I did a little expirement: user-select: text; works fine but user-select: auto; not. I'll make a PR for this

RichardLindhout added a commit to RichardLindhout/react-native-web-1 that referenced this issue Sep 17, 2020
@RichardLindhout
Copy link
Contributor Author

Closing this as for nested elements there is a PR up: #1742.

But maybe we could document this differente somewhere for library owners so they can make web support better (e.g. set selectable={false} inside elements on buttons

RichardLindhout added a commit to RichardLindhout/react-native-vector-icons that referenced this issue Sep 23, 2020
oblador added a commit to oblador/react-native-vector-icons that referenced this issue Feb 13, 2022
* Make text non-selectable on web too

Context: necolas/react-native-web#1741

* Add default of selectable=false to have the same behaviour across platforms

* Fix prettier of icon-button.js

Co-authored-by: Joel Arvidsson <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants