Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> For example, type a single character in the email input in the example in the article and notice that the field immediately transitions to the error state even though you’re still typing.

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.)



> I would recommend using :user-invalid and polyfilling

Is there a polyfill you can recommend?


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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: