Some people love custom elements, and it seems that even more people are entirely against them. And while I'm leaning towards using them, today I learned a fascinating custom elements take.
I've been reading one of Adam Argyle's excellent component walk-throughs, and Adam shared a tool-tip
custom element that works without the usual customElements.define
JavaScript instruction.
To quote Adam:
You could think of a custom element like a classname with less specificity.
That's an interesting take because it changes the mental model around custom elements! Custom elements are usually used to encapsulate functionality as web components with JavaScript, but one could also use them as another style hook with lower specificity than class selectors. Neat!
And to make the custom element accessible, Adam's example tool-tip
component receives its semantic meaning via ARIA...
<tool-tip role="tooltip">A tooltip</tool-tip>
... and the show/hide functionality is then added via CSS has()
. 😲
:has(> tool-tip):is(:hover, :focus-visible, :active) > tool-tip {
opacity: 1;
transition-delay: 200ms;
}
Very smart!
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4