[TPAC Prep] Customized Built-in Elements: Current Status and Alternatives #67
Replies: 2 comments 5 replies
-
Would love to get more in-depth info on why you'd count this as being true, especially when applied to customized built-ins:
Are you maybe not asking for customized built-ins but instead for a change to the interpreter that allowed autonomous custom elements within Maybe the above context, post interpreter changes, would be where element behaviors would come into play? |
Beta Was this translation helpful? Give feedback.
-
Closing in prep for a replacement report, which I'll submit this week! |
Beta Was this translation helpful? Give feedback.
-
This report summarizes the current status of the customized built-in elements spec, its uses cases, suggested alternatives, and current outlook.
This report does not touch on issues relating to Form Associated Custom Elements or shadow DOM implementations, as other members are currently researching those areas independently.
Customized Built-in Elements
Use cases
1. Creating custom child elements within elements with strict permitted content
Many HTML elements (
table
,picture
,video
,ul
,ol
, etc.) are strictly limited in terms of what types of elements can be used as child content (defined as ‘permitted content’). For example, atable
can only containcaption
,colgroup
,thead
,tbody
ortr
, andtfoot
elements. Similarly, thepicture
element can only contain one or moresource
elements and a fallbackimg
element.Some of these elements (e.g.
ol/ul
,table
) may render unpermitted content (e.g.ol > p > li
), but other elements (such aspicture
) will not. For example, the structurepicture > div > source
will not render thesrcset
specified onsource
, sincesource
must be a direct child ofpicture
.Thus, if an author wishes to create a custom element to be used within one of these parent elements, customized built-in elements are the only way to do so while producing valid HTML structures and functional outcomes.
Example: sortable table
Consider a
table
which can be sorted in ascending or descending order via interactive column headers. Since theth
elements themselves would need to be updated with the relevantaria-sort
attributes whenever the active sort changes (and we would likely want to update the styling of theth
elements themselves to visually indicate the active sort mechanism), we want to expose a customth
element to encapsulate this functionality.However, since the above example uses autonomous custom elements for the
custom-th
element (even if it may internally wrap ath
element), and becausetable
and its sub elements are strict in which HTML elements are considered permitted content, this would produce semantically incorrect and invalid HTML.The solution would be to use a customized built-in element, whereby the built-in
th
element is extended to handle this additional functionality while maintaining semantically correct and valid HTML.At present, however, it is impossible to ship this implementation to all users of evergreen web browsers, as WebKit has declined to implement the customized built-in elements spec (see status section above). We do not consider polyfilling an option as this can be fragile and results in degraded performance for WebKit end users, who make up a significant portion of global web traffic. Thus, patterns such as this example (and any other pattern in which elements with strictly permitted contents might be combined with custom elements) are effectively blocked at present.
2. Extending a built-in element’s behaviour
Extending a built-in element’s behaviour can be desirable even when that element does not need to be contained within a parent with strict permitted contents. This web.dev article contains two such examples — adding a ripple effect to a button, and extending the
img
element to include built in transformations.The above examples could in theory be made possible by wrapping the
button
andimg
elements with an autonomous custom element, however it would result in unnecessarily nested HTML and a level of indirection that is less than desirable.Potential alternatives
In a comment from July of 2023 on the issue stating WebKit’s position on the customized built-in elements spec, WebKit reviewer Ryosuke Niwa cited the following proposals as alternatives:
Outlook
At present, Blink and Gecko’s support for the Custom Attributes/Element Enhancements proposals is unknown (which is understandable, given they’ve shipped the customized built-in elements spec). At the same time, WebKit’s official position and prioritization for implementing these proposals is also unknown. This impasse paints a frustrating picture for complete cross browser support for authors wanting to extend built-in elements with custom functionality and behaviour.
As can be seen from the GitHub issue discussing WebKit’s position on the customized built-in elements spec, a great many authors are eager for a solution to this challenge. This may also negatively impact end users, who may be served substandard implementations (via polyfills or inconsistent functionality) until viable solutions are available to authors on all modern web clients. Decisive collective action is needed from browser vendors and other interested parties to collaborate on and resolve this roadblock as soon as possible.
Beta Was this translation helpful? Give feedback.
All reactions