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

[Select] Required in select component not working #610

Open
rogefm opened this issue Oct 16, 2024 · 6 comments
Open

[Select] Required in select component not working #610

rogefm opened this issue Oct 16, 2024 · 6 comments

Comments

@rogefm
Copy link

rogefm commented Oct 16, 2024

I'm using the required to validate the form using HTML validation. All inputs do a good job, but the select component with required = true lets the form submit even without having an option selected.

@kevinmitch14
Copy link

Working for me, it's best to create a reproduction of the issue.

Screenshot 2024-10-16 at 14 51 47

@rogefm
Copy link
Author

rogefm commented Oct 16, 2024

Sorry, I was creating a reproduction to share
https://codesandbox.io/p/sandbox/yy8ttr

@rogefm
Copy link
Author

rogefm commented Oct 16, 2024

Working for me, it's best to create a reproduction of the issue.

Screenshot 2024-10-16 at 14 51 47

If you can share the code I can look for the differences.

@kevinmitch14
Copy link

kevinmitch14 commented Oct 16, 2024

It's because you are setting the value to "". It's selecting option1 as a result and not triggered the native required.

const [value, setValue] = React.useState("");

For example if you use const [value, setValue] = React.useState(undefined);, the required message will show up

Why it is selected option1, when "" is passed as value, I'm not sure.

@rogefm
Copy link
Author

rogefm commented Oct 16, 2024

Cool, you are right. But is weird, that most of the input from radix doesn't allow the value be undefined or null, but the select yes 🥲
Thx for the help. Still, I'm not sure if it is not a bug, but ok if you want to close the issue.

@kevinmitch14
Copy link

I'm not too sure why having value={""} would result in "option1" being the active value though. Maybe it's a bug, I'm not too sure. If you think it is, maybe best to have a look at radix/primitives. PS. I'm not a maintainer!

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