-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Fix handling of onClick event for accessibilityRole="link" #1353
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
Conversation
Why are you using |
@Neclos we are using I believe there's an issue for this specifically but I'm on mobile at the moment so having trouble finding it |
Hi @necolas, thanks for taking a look! :) Like @loudwinston, I avoid ScrollViews and Touchable. I just had too many issues, and want an app that feels native to the web. By that I do not mean an iOS/Android app that also runs on the browser, but a fully fledged "regular" web app. In addition to that, the app is also a Smart TV app which triggers click events when using the "OK" button on the remote control. I did try to do it properly, e.g. I actually have a body scroller prototype locally, but it does not solve the broader issues. Generally my opinion is that RNW enhances the web platform and should still allow the web apis to be usable. So while this might seem like a hack, I sincerely do not feel that way for the click event since it should be exposed anyway. I find it extremely irritating that the click handling depends on what element is used. If Thanks |
@EyMaddis @necolaa to clarify, the application I am working on does use Touchables and ScrollViews. We had to start using There's some refactoring we want to do to make these Touchables into actual links on the web (and perhaps remove the ScrollViews as well), but the app started as a native app and was modified to also work on the web at a later time, so a lot of the code is very native focused at this time. It would be preferable if we didn't have to fork RNW to make this behavior work for us. I don't know the details of the changes that are being made to the responder system or how this |
@necolas any chance you can take another look at this? :) |
None of this is stable, so relying on |
@necolas However right now, there is no other way to fix the issues. It seems that regular views are always part of the responder system so it seems to be impossible to use their functionality. I do not see the responder system getting fixed properly in the next few weeks. I tried, but quickly noticed that this is a deep dive to reacts internals. On the other hand, the lines right after that fix officially support and use react-native-web/packages/react-native-web/src/exports/createElement/index.js Lines 86 to 96 in fb93019
I agree with the problem that react native introduces via its own |
@loudwinston I now use https://www.npmjs.com/package/patch-package with the following: You might use another version of RNW, if follow the instructions from patch-package and manually fix it in your project diff --git a/node_modules/react-native-web/dist/exports/createElement/index.js b/node_modules/react-native-web/dist/exports/createElement/index.js
index 903f855..8152350 100644
--- a/node_modules/react-native-web/dist/exports/createElement/index.js
+++ b/node_modules/react-native-web/dist/exports/createElement/index.js
@@ -72,7 +72,7 @@ var adjustProps = function adjustProps(domProps) {
// preceding mouse events in the responder system.
if (isLinkRole && onResponderRelease) {
- domProps.onClick = function (e) {
+ domProps.onClick = onClick || function (e) {
if (!e.isDefaultPrevented() && !isModifiedEvent(e.nativeEvent) && !domProps.target) {
e.preventDefault();
}
|
0.13 resolves all the issues that using |
This is a extracted from #1348 in order to separate the discussion of the two issues.
By default
onClick
and other DOM based props are passed down to the element likediv
s, but not for links!This is currently not in the documentation, but used in this example and in the official guides (here:
onMouseEnter/Leave
) from @necholas!Using
onClick
is crucial when avoiding Touchables/ScrollViews in to not inherit issues from #1219. Mobile browsers already solve scroll-based issues if we use regular click events.This PR aims to allow just that and fix the link handling, as all other RNW elements support the
onClick
.This results in problems like:
I hope that you hear me out. Thanks for the great library! 👍