[Text Field] Validity pseudo classes should apply styling
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 99.1k
- Forks
- 32.5k
- Avg merge
- 2d 17h
- Merged PRs (30d)
- 106
Description
Duplicates
- I have searched the existing issues
Latest version
- I have tested the latest version
Summary 💡
MUI should style form inputs on the :invalid and :valid pseudo classes, similar to how bootstrap works for form validation: https://getbootstrap.com/docs/4.6/components/forms/#validation.
This way, I can use the native html form validation and things just work.
Examples 🌈
E.g., if I have any rendered input under the hood with props like <input type="text" pattern="[0-9]*" required/>, any time the value changes to an empty value or a non number, it will be marked as :invalid. This should auto-style the input into the error state as described here. Bonus points if you could also set custom validity messages on props that in turn calls setCustomValidity(message).
Motivation 🔦
Without this feature, I'm stuck doing manual form validation. That is, I am required to have some function onValidate that will check the form input validity and toggle the error property. If MUI worked this way, I could just use all native html input validation properties and things would just work.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by inspecting how MUI Text Field renders its underlying input and how the error state is currently applied. Use the native HTML validation example with required and pattern attributes to check the :invalid and :valid states. Done means rendered inputs receive the expected validation styling without manual error toggling; custom validity messages are an optional extension mentioned in the issue.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, react
- Domain
- frontend
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100