Prevent focus on press of a button
Provide a general summary of the feature here
I am developing a rich text editor. When text is selected and a formatting button in the toolbar is clicked, the mobile keyboard closes because the focus shifts to the button. To prevent this, I tried adding event.preventDefault() to onMouseDown, but this doesn't work because usePress employs various other events to change focus, making onMouseDown inaccessible.
It will be great to have a prop named preventFocusOnPress if we cannot have onMouseDown
๐ค Expected Behavior?
There should be a way to prevent focus on buttons.
๐ฏ Current Behavior
There is no way to prevent focus on click of a button
๐ Possible Solution
No response
๐ฆ Context
In text editors, even when you click a button, the focus should not shift from the main textbox but there is no way to do that in the current button hooks.
๐ป Examples
No response
๐งข Your Company/Team
PSPDFKit
๐ท Tracking Issue
No response
We actually have preventFocusOnPress in useButton already but it is undocumented since it was more for specific use cases (calendar cells, combobox button, etc) and we didn't want it to be misused. I can bring it up with the team to see if we want to pivot on that and expose it fully.
Talked with the team, we are ok with exposing it as public api, will need to document it and mention that it should only be used in particular use cases.
This is great. Thank you for taking the time and coming up with a solution this fast.