Csswg-drafts: [selectors-4] :defined

Created on 2 Feb 2018  ·  6Comments  ·  Source: w3c/csswg-drafts

HTML defines :defined: https://html.spec.whatwg.org/multipage/semantics-other.html#selector-defined.

  1. Is that enough for a definition of a new pseudo-class?
  2. Is it fine for HTML to define this?
  3. Should Selectors contain a registry of externally defined selectors?

(I'm asking this in part since we're considering a :heading(level) pseudo-class.)

See also: https://github.com/w3c/webcomponents/issues/665.

cc @domenic @snuggs

Needs Edits selectors-4

Most helpful comment

:defined matches all elements that had no problem during construction, roughly. It's useful since you can now implement your own element class and sometimes you want to match elements for which the constructor has not yet run (or vice versa).

As for headings, that sounds reasonable, though we'll run into the data model issue again (though arguably we do already for other things, so it doesn't necessarily add to the problem).

All 6 comments

Can I get a layperson's definition of :defined and what it's used for? :)

Wrt :heading(), we've gotten requests for this an declined them so far. If it's something we want to add, we can add it to Selectors--it's definitely not an HTML-specific concept, so it should go into Selectors and not HTML.

:defined matches all elements that had no problem during construction, roughly. It's useful since you can now implement your own element class and sometimes you want to match elements for which the constructor has not yet run (or vice versa).

As for headings, that sounds reasonable, though we'll run into the data model issue again (though arguably we do already for other things, so it doesn't necessarily add to the problem).

To embellish on @annevk's statement with an example.

<style>
  foo-bar { visibility: hidden }
  foo-bar:defined { visibility: show }
</style>

<foo-bar>You can't see me...yet</foo-bar>

If a user wanted to preserve real estate but not display until element is defined.

@annevk does this help or hurt?

The CSS Working Group just discussed :defined, and agreed to the following:

  • RESOLVED: Add :defined to selectors L4

The full IRC log of that discussion
<dael> Topic: :defined

<dael> github: https://github.com/w3c/csswg-drafts/issues/2258

<dael> fantasai: HTML defines :defined pseudo class in its spec, in general we define in selectors and HTML refines. So should :defined be defined in selectors?

<dael> fantasai: Matches all elements that had no problem during constructions

<dael> Rossen: Any reason why it shouldn't be defined in selectors?

<dael> fantasai: Very HTML specific currently. That's the only reason I can think of

<dael> Rossen: Not crazy about the name, it's a little too generic

<dael> florian: Would fail to match on custom elements not defined properly and any element whose semantics are unknown to browser?

<dael> fantasai: Don't know

<dael> florian: Reading example that seems to be the case. If using on a not known element it won't match.

<dael> florian: Does make it non-HTML specific even if use cases are HTML specific

<dael> florian: Seems like we should do this, but also study more

<dael> fantasai: It's impl afaict

<dael> Rossen: Impl in blink?

<dael> fantasai: Not registering as invalid in test case.

<dael> emilio: Impl in blink, gecko, and webkit

<fantasai> http://software.hixie.ch/utilities/js/live-dom-viewer/?%3C!DOCTYPE%20html%3E%0A%3Cstyle%3E%0Ahtml%3Adefined%2C%20foo%3Adefined%20%7B%20border%3A%20solid%20green%3B%20%7D%0A%3C%2Fstyle%3E%0A%3Cfoo%3EThis%20is%20a%20test%3C%2Ffoo%3E

<tantek> are there tests for this?

<dael> Rossen: If this has impl in various UA and since it's a selector makes sense as part of selectors unless we're against it in the way it's defined. We should accept it and refine

<dael> florian: Sounds good

<dael> Rossen: Other comments or Objections to adding :defined to selectors L4?

<dael> RESOLVED: Add :defined to selectors L4

@annevk @fantasai is this good to close now that is on track with CSS Level4?

I think it would make sense to close this when the PR that adds this to Selectors Level 4 lands.

Was this page helpful?
0 / 5 - 0 ratings