-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
feat: Support onClick as an alias for onPress #7891
base: main
Are you sure you want to change the base?
Conversation
## API Changes
@react-aria/dnd/@react-aria/dnd:DropResult DropResult {
dropButtonProps?: AriaButtonProps
- dropProps: HTMLAttributes<HTMLElement>
+ dropProps: DOMAttributes
isDropTarget: boolean
} |
Thanks for opening up this discussion @devongovett. I would like to first inform myself better with the issues How much of the issues you described in (Building a Button Part 1: Press Events) is still relevant? It's been 5 years since the article was published — I assume browsers had at least fixed some of the inconsistencies mentioned in the article. Or are there as well other sources to check which issues |
Some of it is still relevant, but there have been quite a few improvements. I'm planning on writing an update to that blog post series soon. The major thing that changed recently is that buttons now receive focus consistently in all browsers, so this part is no longer necessary. Therefore, as of #7542 we no longer use Also in that PR, we now trigger However, other behaviors described in the original blog post, such as text selection behavior, active state, hover state, cancelation, virtual clicks, repeating keyboard events, etc. still apply. I believe it's still important to handle those for a good experience, especially on mobile/touch devices, but luckily we can now rely on native events more. |
Looking good @devongovett!
I think your onPress implementation makes a lot of sense for common UI components – onClick would benefit from that work too, and it may not be that much different from native behavior. In your example of filtering only left clicks, browsers do this too, right? I don't trust my memory, so quickly tested this with a mouse on both a
What are the cases? Anything beyond keyboard events?
If I saw a strikethrough, but it worked, though I couldn't find info in the docs, I'd be a little confused. Would it be okay to treat onClick as a sort of "compatibility alias", not a deprecated feature, and the docs explain this while recommending onPress when possible? |
Proposal for discussion. See this discussion: https://x.com/deebovv/status/1897355956188537016
In particular:
We solved the second case with
<Pressable>
added in the last release. The first case of using a RAC Button as a trigger for a third-party component that passes inonClick
remains.This PR basically treats
onClick
as an alias foronPress
. It gets fired at the same times. If we have a nativeMouseEvent
event available, it gets passed to the handler. If not, e.g. in a keyboard event, we synthesize a fake click event and pass that. This matches what browsers do for certain elements: https://html.spec.whatwg.org/#fire-a-synthetic-pointer-event.Questions:
usePress
to avoid edge cases. For example, we only fireonPress
for left clicks, not right clicks, and we don't fireonPress
for repeating keyboard events. Seems like matching this inonClick
would be good to take advantage of this behavior, but could be unexpected that it doesn't match the browser behavior foronClick
. But if people will be usingonClick
just because they're used to that name, they'd lose out on some of this improved behavior, so I lean towards having it matchonPress
. Thoughts?onClick
in cases where the browser doesn't do so?onClick
as@deprecated
in the prop definition, which means it'll be omitted from the docs. This way we nudge people towardonPress
but it works regardless, e.g. when used with third party libraries. Also means it'll be rendered with a strikethrough in people's IDEs. But, there's no more console warning. Thoughts?