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

Prevent focus on press of a button #6533

Open
ritz078 opened this issue Jun 12, 2024 · 3 comments
Open

Prevent focus on press of a button #6533

ritz078 opened this issue Jun 12, 2024 · 3 comments
Labels
enhancement New feature or request

Comments

@ritz078
Copy link
Contributor

ritz078 commented Jun 12, 2024

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

@ritz078 ritz078 changed the title Prevent focus change on press of a button Prevent focus on press of a button Jun 12, 2024
@LFDanLu
Copy link
Member

LFDanLu commented Jun 12, 2024

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.

@LFDanLu
Copy link
Member

LFDanLu commented Jun 12, 2024

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.

@LFDanLu LFDanLu added the enhancement New feature or request label Jun 12, 2024
@ritz078
Copy link
Contributor Author

ritz078 commented Jun 13, 2024

This is great. Thank you for taking the time and coming up with a solution this fast.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: ✏️ To Groom
Development

No branches or pull requests

2 participants