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
Required select is valid when no option is selected #455
Comments
This is by design and documented here:
This behavior is more in line with how |
Sorry, I didn't notice that in the docs. In my opinion, developers should handle the state and styling of form fields themselves instead of the library. That's what for example Angular is doing. Example: https://angular.io/guide/form-validation#validating-input-in-template-driven-forms Here the error message is displayed only when the field state is The problem is that a new user of this library (me) can expect that the If I had to choose, I would say that Unfortunately, I can not think of any non-breaking change that would satisfy what I just described and that would also make sense. The workaround for me is to use |
Admittedly, I didn't think about this too much when I was dealing with form validation. I think you're right, though. The property should probably reflect whether the input is invalid regardless of interaction. |
Fixed in 1e4de5f. This will be released in beta.44. |
Describe the bug
Property
invalid
of<sl-select required>
should betrue
by default because no option is selected yet. Instead it isfalse
.To Reproduce
I prepared example in Lit playground: example
Expected behavior
The included example should have
invalid: true
instead ofinvalid: false
by default. To show the correct value, I also included "inner invalid" value which reflects the valid state of the underlying<select>
(input.validity.valid
).Desktop (please complete the following information):
The text was updated successfully, but these errors were encountered: