Skip to content

CustomStateSet for custom elements #56

Closed

Description

@calebdwilliams

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.

Activity

  1. added
    topic: css
    topic: web apis
    venue: WICG
    from: Google
    on Sep 25, 2022
  2. annevk commented on Oct 7, 2022

    @annevk
    Contributor

    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.

  3. annevk commented on Nov 11, 2022

    @annevk
    Contributor

    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.

  4. rniwa commented on Nov 12, 2022

    @rniwa
    Member

    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.

  5. annevk commented on Nov 14, 2022

    @annevk
    Contributor

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

  6. rniwa commented on Nov 14, 2022

    @rniwa
    Member

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

  7. annevk commented on Nov 15, 2022

    @annevk
    Contributor

    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.

  8. annevk commented on Nov 18, 2022

    @annevk
    Contributor

    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?
  9. annevk commented on Jan 27, 2023

    @annevk
    Contributor

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

  10. moved this from Unscreened to Needs position in Standards Positions Review Backlogon Mar 23, 2023
  11. moved this from Needs position to Needs assignees in Standards Positions Review Backlogon Mar 27, 2023
  12. moved this from Needs assignees to Needs position in Standards Positions Review Backlogon Mar 27, 2023
  13. annevk commented on Sep 25, 2023

    @annevk
    Contributor

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

  14. moved this from Needs position to Position identified in Standards Positions Review Backlogon Oct 11, 2023
  15. moved this from Position identified to Done in Standards Positions Review Backlogon Oct 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

from: Googleposition: supporttopic: csstopic: web apistopic: web componentsvenue: WICG

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions