Re: [csswg-drafts] [css-shadow-parts] Unifying ::part() and ::--foo (#4900)

> (Alternately, we just use ::part, no parens, to name all the parts, and all the part names are classes, like ::part.day.weekend. I'd be happier with this variant.)

This is actually very close to what I've been thinking lately.

I'm not happy with the conflation of tag-like and class-like behavior in part names. I strongly feel that shadow parts should really just be custom pseudo-elements and have a single tag-like name, just like built-in pseudo elements do. I want to expose built-in behavior not create something special and different.

I do see the value in the additional class-like behavior, and my current thinking is that could be exposed as classes of the pseudo-element to selectors. There's no way for anything else to assign classes to pseudo-elements so why not? Note that actual classes assigned to a part should not break the encapsulation of the custom element and be visible outside it.

e.g.
```
<custom-calendar>
    <shadow-root>
      <custom-day part='day' part-class='weekend holiday' class='internal-class'>1</custom-day>
    </shadow-root>
  </custom-calendar>
```

(I don't care what the 'part-class' attribute is really called)

A weekend holiday would be selected via:
`custom-calendar::--day.holiday.weekend { ... }`

The 'internal-class' can be used by stylesheets attached to the &lt;custom-calendar> but is not exposed to anything that contains a &lt;custom-calendar>. If the &lt;custom-day> itself exposes custom state or additional parts, those would simply be exposed and could be selected like:
`custom-calendar::--day.holiday.weekend:--active::--day-part { ... }`

I'd be ok with parts having multiple part names, but those would be an 'or', e.g. you could select &lt;custom-day part='foo bar'> as either `::--foo` or `::--bar`, but never `::--foo::--bar` because that would be a bar part inside the foo part. (Which also brings the question if the part name should be specified as `part='--foo'`, I think so). Multiple tag-like part names would allow flexibility to evolve the internals of a custom element without necessarily breaking users, but then can't be (ab)used for class-like behavior. 

Alternatively we could define the first part name to be the tag-like name and others to be class-like, but I think that's problematic when you start manipulating them, e.g. toggle the first one off and you just redefined the tag-like name.

If the class syntax doesn't work for some reason, my fallback would be exposing the part's class-like names as param of the pseudo-element, e.g.
`custom-calendar::--day(holiday weekend) { ... }`

Either approach gets rid of `::part` and aligns this with custom pseudo-classes.

-- 
GitHub Notification of comment by plinss
Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/4900#issuecomment-625592040 using your GitHub account

Received on Friday, 8 May 2020 02:20:17 UTC