Re:Styling form states without JavaScript
by coder543 on Thursday November 17, 2022 @09:40PM
(#33649225)
> I would recommend using :user-invalid and polyfilling
Is there a polyfill you can recommend?
Re:Styling form states without JavaScript
by chrismorgan on Thursday November 17, 2022 @10:41PM
(#33649865)
No idea, sorry. I haven’t had cause to want this sort of thing in the last couple of years (or I’d have done it myself if no one else has). It’s not unlikely, in fact, that no one has actually written a suitable polyfill yet, of similar nature to :focus-visible polyfills. But if one wants to implement such a thing, :focus-visible polyfills are a decent starting place to look at and think about.
The solution for this is :user-invalid. Firefox has had it for a year and a half, WebKit has https://github.com/WebKit/WebKit/pull/5958 hopefully landing soon, Chromium has no activity on https://bugs.chromium.org/p/chromium/issues/detail?id=115606.... For fresh development these days, I would recommend using :user-invalid and polyfilling, rather than implementing your own very similar semantics in your own way in JS.
See https://developer.mozilla.org/en-US/docs/Web/CSS/:user-inval... for a demo.
(:user-invalid as an alternative to :invalid joins the list of presentational nuance pseudoclasses that allow you to match what browsers themselves do in their default styling, joining :focus-visible which is an alternative to :focus.)