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

:blank pseudo-selector support (re form fields) #179

Closed
brandonmcconnell opened this issue Oct 2, 2022 · 11 comments
Closed

:blank pseudo-selector support (re form fields) #179

brandonmcconnell opened this issue Oct 2, 2022 · 11 comments
Labels
focus-area-proposal Focus Area Proposal

Comments

@brandonmcconnell
Copy link

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.

Related discussions:

Specification

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

Tests

Struggling to find any tests

@brandonmcconnell brandonmcconnell added the focus-area-proposal Focus Area Proposal label Oct 2, 2022
@gsnedders gsnedders added this to the Interop 2023 milestone Oct 2, 2022
@foolip
Copy link
Member

foolip commented Oct 3, 2022

I also can't find any tests. All matches for :blank in WPT are for about:blank, and typos of it fixed in web-platform-tests/wpt#36222.

@foolip
Copy link
Member

foolip commented Oct 3, 2022

@foolip foolip moved this to Proposed in Interop 2023 Oct 7, 2022
@foolip foolip removed this from the Interop 2023 milestone Oct 7, 2022
@annevk
Copy link
Member

annevk commented Oct 28, 2022

This seems like a reasonable feature, but the HTML standard needs to define how this actually works for its various elements. As far as I can tell that work hasn't been done.

E.g., does this work for textarea elements? What does it mean for <input type=range> or <input type=checkbox>?

@brandonmcconnell
Copy link
Author

@annevk Good call out! Sharing some thoughts in the related issue you opened. Thanks!

@smaug----
Copy link

Would :blank apply when placeholder is set?

@foolip
Copy link
Member

foolip commented Nov 11, 2022

In the State of CSS 2022 question about browser incompatibilities, there were no mentions of :blank.

(I'm not commenting on all proposals where there wasn't any signal from State of CSS, but thought I would here because it's similar to #180 where I did comment.)

@foolip
Copy link
Member

foolip commented Nov 11, 2022

In the MDN short survey on CSS & HTML, "CSS :blank and :empty pseudo-classes" was selected by ~19% of survey takers, putting it in the middle third of the 20 options. (There is some uncertainty as with any survey data.)

Since :blank and :empty were bundled we can't say which of them resonated more. (This was done to reduce the total number of options.)

@nairnandu
Copy link
Contributor

Thank you for proposing the :blank pseudo-selector for inclusion in Interop 2023.

We wanted to let you know that this proposal was not selected to be part of Interop this year. The specifications for :blank are not yet complete enough to allow interoperable implementations. To make progress on this area in the future it will first be necessary to ensure that the feature has a clear specification in a standards track document.

For an overview of our process, see the proposal selection summary. Thank you again for contributing to Interop 2023!

Posted on behalf of the Interop team.

@brandonmcconnell
Copy link
Author

@foolip @nairnandu Could we look into resurrecting this one for Interop 2024 as well?

@annevk
Copy link
Member

annevk commented Sep 25, 2023

I'm not convinced we have seen enough progress on w3c/csswg-drafts#1967 and whatwg/html#8451.

@brandonmcconnell
Copy link
Author

brandonmcconnell commented Sep 25, 2023

@annevk Fair point. whatwg/html#8451 seems pretty thorough to me, but w3c/csswg-drafts#1967 may still require further discussion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
focus-area-proposal Focus Area Proposal
Projects
No open projects
Status: Proposed
Development

No branches or pull requests

6 participants