-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Why is preventDefault
not made available on press events?
#963
Comments
We preventDefault in many place in usePress https://github.com/adobe/react-spectrum/blob/main/packages/%40react-aria/interactions/src/usePress.ts#L302 |
Thanks for getting back to me @snowystinger . I'm looking forward to hearing more! |
Can you tell us which event it is that you need to prevent default on? |
@snowystinger I need to call |
Sorry, can you tell if it's the default of the mouse/pointer down, up? there are several events present in the construction of onPress |
Also, what is the dom structure for this? I'm envisioning something along these lines and want to double check
|
@snowystinger That is exactly the DOM structure we're looking at; a |
Ah, that is not valid HTML, so you probably shouldn't be doing that.
|
o, and this is probably why we aren't exposing preventDefault on the press events
|
@snowystinger While I know we shouldn't be doing this; the unfortunate fact is we are π I think exposing |
Well you may be in luck, it looks like we're doing something odd here https://github.com/adobe/react-spectrum/blob/main/packages/%40react-aria/interactions/src/usePress.ts#L228 in the meantime, you could use the deprecated onClick prop to handle it yourself until you can get the button out of the link :) |
Thank you @snowystinger ! I'll do that for the time being π |
@snowystinger I think |
I'm not sure I follow your concern @deebov this is the temporary workaround I was suggesting https://codesandbox.io/s/busy-hooks-dhx4u If you have a concern about something we might break by us default calling preventDefault onClick would you mind commenting on this PR #904 We do have some anchor tag handling in usePress, though we'd optimally like to remove it from there to a more appropriate aria hook(s) https://github.com/adobe/react-spectrum/blob/main/packages/@react-aria/interactions/src/usePress.ts#L599 |
I have a link button with an onPress, I want the link to be just there but customize what happends when it is clicked. Is there any way to prevent the default link behavior? |
Sure, if you're just using the hooks libraries, add an onClick to the anchor element and prevent default in it. |
It would be helpful to at least add this to the documentation. I have a similar use case, an Instead of providing the |
That's a reasonable suggestion. Should it go on |
β Question
Why is
preventDefault
not available inPressEvent
?π¦ Context
I'm replacing the guts our of style system with
react-spectrum
and ran into an incompatibility with our codebase becausepreventDefault
is not inonPress
fromuseButton
(orusePress
).There's a few use cases. First, we have clickable rows in a list that have a delete button inside of them. The delete button needs to prevent the default so the row itself won't navigate away.
π» Code Sample
π Your Environment
π§’ Your Company/Team
Apollo GraphQL π
The text was updated successfully, but these errors were encountered: