Open brandonferrua opened 4 years ago
At first I thought restricting part
was due to the fact that there is already a part
property on Element
. But we don't have the same restriction for @api classList
, @api setAttribute
, etc. We specifically restrict part
:
It looks like originally this restriction was added in https://github.com/salesforce/lwc/pull/49 (here). @pmdartus Do you have some context for why this restriction exists?
Do you have some context for why this restriction exists?
I don't recall the discussion. I assumed we did restrict the usage of the part
public property due to future-proofing concerns.
This seems similar to me to @api ariaLabel
– we would need to make sure that the property and attribute are properly reflected, and that an LWC component can set the property/attribute on a child.
Is your feature request related to a problem? Please describe.
I'd like to propose removing the restriction of using
part
as a getter/setter, e.g.@api part
I am able to decorate my HTML with
part
as a content attribute, e.g.<button part="button">
. When using both nativeshadowDOM
andsyntheticShadow
I can access thispart
attribute with an attribute selector:If I choose to use native
shadowDOM
then I get upgraded and can use the::part
pseudo-element with full interop withsyntheticShadow
since this namedpart
is still treated like a content attribute.Since
::part
pseudo-element is simply a string and a content attribute is simply a string, they are both apart of theattribute-list
comes fromNamedNodeMap
, what is the harm in accessingpart
as a getter/setter if the type is restricted to a string?By removing this restriction, customers can add new
part
names to decorated nodes, thus increasing the extensibility of this styling capability.Describe the solution you'd like
Remove the restriction of
part
as a getter/setter and type check it as a string.By doing so, a customer could provide CSS through an attribute selectors in both
syntheticShadow
and nativeshadowDOM
. When choosing to use nativeshadowDOM
they will get upgraded and have access to using::part
pseudo-element immediately since the support comes from the UA.Describe alternatives you've considered
Polyfill
::part
intosyntheticShadow
or using a non-standard term to mimic the same behavior ofpart
, i.e.hook
cc: @pmdartus @diervo