Monday, May 20, 2024
HomeJavaScriptA JavaScript-free customized ingredient implementation

A JavaScript-free customized ingredient implementation


Some individuals love customized components, and evidently much more individuals are totally towards them. And whereas I am leaning in the direction of utilizing them, immediately I discovered a captivating customized components take.

I have been studying one among Adam Argyle’s glorious part walk-throughs, and Adam shared a tool-tip customized ingredient that works with out the same old customElements.outline JavaScript instruction.

To cite Adam:

You can consider a customized ingredient like a classname with much less specificity.

That is an fascinating take as a result of it modifications the psychological mannequin round customized components! Customized components are often used to encapsulate performance as net parts with JavaScript, however one may additionally use them as one other type hook with decrease specificity than class selectors. Neat!

And to make the customized ingredient accessible, Adam’s instance tool-tip part receives its semantic that means through ARIA…

<tool-tip position="tooltip">A tooltip</tool-tip>

… and the present/conceal performance is then added through CSS has(). 😲


:has(> tool-tip):is(:hover, :focus-visible, :energetic) > tool-tip {
 opacity: 1;
 transition-delay: 200ms;
}

Very good!

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments