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

[selectors-4] :blank pseudo-selector support (re form fields) #595

Closed
brandonmcconnell opened this issue Oct 25, 2023 · 1 comment
Closed

Comments

@brandonmcconnell
Copy link

This is a copy from last year's Interop 2023 proposal for this same feature: #179

Description

:blank is a pseudo-selector that allows CSS to target a form field when it is blank/unpopulated.

Quoting the spec:

The :blank pseudo-class applies to user-input elements whose input value is empty (consists of the empty string or otherwise null input).

Rationale

There's currently no viable way to target a blank form field. The most common vanilla workaround for this so far is to mark the field as required and then check for :valid along with some pattern matching, however there are quite a few fundamental problems with that approach:

  • What if there is already some non-blank-related validation logic at play which conflicts with the mere non-blank check?
  • What if the form field should NOT be required but still styled differently when blank for aesthetic purposes?

More recently, another workaround for this that has been growing in popularity is :placeholder-shown but this doesn't appear to work when there is no placeholder set.

Open issues:

Related discussions:

Specification

https://w3c.github.io/csswg-drafts/selectors-4/#blank

Tests

No tests yet, but fully spec'd and actively being discussed in the open issues listed above

@foolip
Copy link
Member

foolip commented Nov 2, 2023

Hi @brandonmcconnell, I'm going to close this for the same reason as #594. However, I'll add that it seems like a relatively small implementation effort. If there is a pull request for WHATWG HTML to resolve whatwg/html#8451 and test written in WPT, it's the kind of thing that could be done quickly outside of Interop. It seems like a sensible feature, and if you think it's stuck in some process/discuss, I'd be happy to take a look if requested.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants