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

Inputs that are initially disabled are always valid. #473

Closed
straversi opened this issue Jun 24, 2021 · 2 comments
Closed

Inputs that are initially disabled are always valid. #473

straversi opened this issue Jun 24, 2021 · 2 comments
Assignees
Labels
bug Things that aren't working right in the library.

Comments

@straversi
Copy link
Contributor

straversi commented Jun 24, 2021

Describe the bug

When an input is initially disabled, it is valid after enabling it, even when it shouldn't be.

For example, start with an <sl-input type="text" disabled required></sl-input>. Remove the disabled. Check the invalid property. It is false, even though the input is empty and required.

To Reproduce

Reproduced here in this lit playground.

Expected behavior
invalid should be true in the case described above.

I love your components! Thank you so much for your work ❤️

@straversi straversi added the bug Things that aren't working right in the library. label Jun 24, 2021
@claviska claviska added the good first issue This bug or task is a good first issue for new contributors. label Jun 24, 2021
@claviska
Copy link
Member

claviska commented Jun 24, 2021

Thanks for reporting this, and for the repro. This is happening because checkValidity() reports true when an input is disabled. The solution is probably to watch disabled and set update input.invalid after the input is no longer disabled.

This probably affects most other form controls, too. It's a good first issue for anyone who wants to take a stab at it. (I'm trying to finish up the analyzer migration before moving onto anything else.)

I haven't gotten around to input tests yet, but this would be a great thing to test for once fixed.

@claviska claviska removed the good first issue This bug or task is a good first issue for new contributors. label Jun 25, 2021
@claviska
Copy link
Member

This was fixed by updating the input's disabled state and rechecking validity. I'm setting it directly on the input instead of waiting for the next update to avoid having to wait two updates for the correct validity.

Update: I moved the logic into @watch decorators in a28942f.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Things that aren't working right in the library.
Projects
None yet
Development

No branches or pull requests

2 participants