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

How to prevent selecting option of Radix Select on right click #3321

Open
shirshendubhowmick opened this issue Jan 15, 2025 · 3 comments
Open

Comments

@shirshendubhowmick
Copy link

With the Redix Select demo here:
https://www.radix-ui.com/primitives/docs/components/select

It looks like an option can be selected with a right click also, I want to prevent this behaviour, i.e. only select an option using left click.

Since the documentation doesn't talk much about these events, can anyone help me with how can I achieve it ?

@shirshendubhowmick shirshendubhowmick changed the title How to prevent selecting element from Redix Select on right click How to prevent selecting option of Radix Select on right click Jan 15, 2025
@FredrikMWold
Copy link

html elements have an event handler called onContextMenu. I haven't tested it, but you could likely pass a function to it that calls e.preventPropagation() or e.preventDefault().

@shirshendubhowmick
Copy link
Author

Just to be clear I want the default behaviour on right click, I don't want an option to be selected on right click (which is the current behaviour)

As far as I know onContextMenu event fires when user attempts to open a context menu, which I don't want to prevent.

@FredrikMWold
Copy link

That seems a bit trickier since Radix strictly follows browser standards. With a standard HTML <select> menu, right-clicking selects an option instead of opening the context menu—that's the default browser behavior.

What's the reason you're looking for this behavior?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants