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

Allow nested Pressables to bubble their hover state to parent pressables #1875

Open
roryabraham opened this issue Jan 14, 2021 · 4 comments
Open
Labels
project:react-native-web Issue associated with react-native-web

Comments

@roryabraham
Copy link
Contributor

Is your feature request related to a problem? Please describe.
When you have a nested Pressable contained within another Pressable, the hover state of the inner Pressable cannot easily be shared with the parent Pressable. I encountered this problem when trying to make a menu that displays when an element is hovered over.

This code sandbox illustrates the problem I'm having.

Describe a solution you'd like
I understand that this isn't always the desired behavior, so perhaps just adding a boolean prop to the Pressable component such as shouldBubbleHoverState, would do the trick.

Describe alternatives you've considered
A temporary workaround is to use a <TouchableOpacity /> instead of a <Pressable /> for the nested element. This has some limitations, however, and would not allow the nested element to take advantage of hoverability too.

Happy to chat some more if you have ideas, need clarification, or can think of other workarounds in the meantime. Thanks!

@roryabraham
Copy link
Contributor Author

I found a workaround that seems to work for me. Use a custom Hoverable for the wrapper and then Pressable for the children. Still think this could be a useful feature.

@nandorojo
Copy link
Contributor

I'm facing the exact same issue. I'd like to use RNW's Pressable, but I suppose I'll rely on a userland solution for now.

@nandorojo
Copy link
Contributor

nandorojo commented Aug 29, 2021

My issue is basically this:

<Pressable testID="menu" onHoverOut={hideMenu}>
  <Pressable testID="trigger" onHoverIn={showMenu} />
  <Dropdown />
</Pressable>

Except that I want to use onHoverIn/onHoverOut from both the child and parent Pressables.

@necolas necolas added the project:react-native-web Issue associated with react-native-web label Jul 2, 2022
@luixo
Copy link

luixo commented Mar 22, 2023

A friendly ping to draw attention to a problem.

joshgachnang added a commit to FlourishHealth/ferns-ui that referenced this issue Aug 16, 2023
I think tooltips got broken in Expo 49, probably the react-native-web
version getting bumped. There's an existing bug for why we can't have
nested Pressables. The fun thing was if you got your mouse into the
corner of an IconButton (IconButtons are round, the surrounding
Pressable is square), you'd get a tooltip, but as soon as you entered
the child Pressable, the tooltip was cleared.

So to fix it, use the new onPointer* events on View from React Native.
These are added since Android and iOS devices can now have mice,
styluses, etc and mobile should support them too. So in our
implementation, we allow tooltips on hover on all 3 platforms, though
normal mobile device still won't get them (because you can't hover with
touch).

necolas/react-native-web#1875
joshgachnang added a commit to FlourishHealth/ferns-ui that referenced this issue Aug 16, 2023
I think tooltips got broken in Expo 49, probably the react-native-web
version getting bumped. There's an existing bug for why we can't have
nested Pressables. The fun thing was if you got your mouse into the
corner of an IconButton (IconButtons are round, the surrounding
Pressable is square), you'd get a tooltip, but as soon as you entered
the child Pressable, the tooltip was cleared.

So to fix it, use the new onPointer* events on View from React Native.
These are added since Android and iOS devices can now have mice,
styluses, etc and mobile should support them too. So in our
implementation, we allow tooltips on hover on all 3 platforms, though
normal mobile device still won't get them (because you can't hover with
touch).

necolas/react-native-web#1875
swanka pushed a commit to FlourishHealth/ferns-ui that referenced this issue Aug 21, 2023
I think tooltips got broken in Expo 49, probably the react-native-web
version getting bumped. There's an existing bug for why we can't have
nested Pressables. The fun thing was if you got your mouse into the
corner of an IconButton (IconButtons are round, the surrounding
Pressable is square), you'd get a tooltip, but as soon as you entered
the child Pressable, the tooltip was cleared.

So to fix it, use the new onPointer* events on View from React Native.
These are added since Android and iOS devices can now have mice,
styluses, etc and mobile should support them too. So in our
implementation, we allow tooltips on hover on all 3 platforms, though
normal mobile device still won't get them (because you can't hover with
touch).

necolas/react-native-web#1875
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
project:react-native-web Issue associated with react-native-web
Projects
None yet
Development

No branches or pull requests

4 participants