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

CustomStateSet for custom elements #56

Closed
calebdwilliams opened this issue Sep 5, 2022 · 9 comments
Closed

CustomStateSet for custom elements #56

calebdwilliams opened this issue Sep 5, 2022 · 9 comments
Assignees
Labels
from: Google Proposed, edited, or co-edited by Google. position: support topic: css Spec relates to CSS (Cascading Style Sheets) topic: web apis Spec relates to web APIs (entry points for script) topic: web components venue: WICG Proposal is incubated in the Web Incubator Community Group

Comments

@calebdwilliams
Copy link

calebdwilliams commented Sep 5, 2022

Request for position on an emerging web specification

Information about the spec

Anything else we need to know

Somewhat related to #47. This has been shipped in Chrome for some time.

This provides an API to allow custom element authors a way to expose internal state to the DOM for matching operations (including CSS and things like document.querySelector).

This is done via the ElementInternals.prototype.states, which is a set of custom states. A naive example would be

class FancyElement extends HTMLElement {
  constructor() {
    super();
    const internals = this.attachInternals();

    this.internals.states.add('--fancy');
  }
}

customElements.define('fancy-element', FancyElement);

This would mean that a newly-constructed instance of fancy-element would match against :--fancy.

@othermaciej othermaciej added topic: css Spec relates to CSS (Cascading Style Sheets) topic: web apis Spec relates to web APIs (entry points for script) topic: web components venue: WICG Proposal is incubated in the Web Incubator Community Group from: Google Proposed, edited, or co-edited by Google. labels Sep 25, 2022
@annevk
Copy link
Contributor

annevk commented Oct 7, 2022

In my mind this is a pretty logical extension of custom elements. Might be good to get input from @nt1m and @anttijk on the selector aspects.

@annevk
Copy link
Contributor

annevk commented Nov 11, 2022

I looked at whatwg/html#8467 today and one thing that struck is me is that maybe this can reuse DOMTokenList rather than introduce a new set-like data structure.

@rniwa
Copy link
Member

rniwa commented Nov 12, 2022

We don't oppose this feature. There might be minor issues like using DOMTokenList and perhaps the use of -- prefix but the overall idea seems good here.

@annevk
Copy link
Contributor

annevk commented Nov 14, 2022

Let's formalize that: I suggest we add the "position: support" label 7 days from now.

@rniwa
Copy link
Member

rniwa commented Nov 14, 2022

Perhaps we should review & give whatever feedback we want to give before we add the label?

@annevk
Copy link
Contributor

annevk commented Nov 15, 2022

Ah, I did give my feedback on DOMTokenList already. If anyone has more substantive feedback on whatwg/html#8467 or wants to review we can certainly wait a bit before adding the label.

@annevk
Copy link
Contributor

annevk commented Nov 18, 2022

About :state(token)vs:--token`:

  1. Switch syntax from :state(foo) to :--foo WICG/custom-state-pseudo-class#6 renamed :state(token) to :--token.
  2. This was shared in Custom pseudo-classes for host elements via shadow roots (:state) WICG/webcomponents#738 (comment) with the Web Components community and @othermaciej objected as result.
  3. A long discussion was had in [css-shadow-parts] Unifying ::part() and ::--foo w3c/csswg-drafts#4900 about changing ::part(token1 token2) to something like ::--token1.token2, but apparently ::part() implementations shipped and everyone forgot about that discussion?! (The issue is still open, but that's probably an oversight?)
  4. Should we rename :--token back to :state(token) so Web Components have internal consistency?

@annevk
Copy link
Contributor

annevk commented Jan 27, 2023

To follow-up here, @rniwa found a further concern: whatwg/html#8467 (comment).

@annevk
Copy link
Contributor

annevk commented Sep 25, 2023

Given that @rniwa's concern has been addressed I once again suggest we resolve this as "position: support" one week from now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
from: Google Proposed, edited, or co-edited by Google. position: support topic: css Spec relates to CSS (Cascading Style Sheets) topic: web apis Spec relates to web APIs (entry points for script) topic: web components venue: WICG Proposal is incubated in the Web Incubator Community Group
Development

No branches or pull requests

4 participants