Based on a conversation yesterday about custom events, I was playing around with strongly typing events for #WebComponents and decided to do a little write-up on it.
#html #javascript
https://dev.to/stuffbreaker/creating-strongly-typed-events-for-web-components-1jem
Another attempt at customized built-ins! Basically class CustomButton extends NativeButton (but with a less obvious API of course)
Explainer: https://github.com/MicrosoftEdge/MSEdgeExplainers/blob/main/ElementInternalsType/explainer.md
Intent to prototype in Blink: https://groups.google.com/a/chromium.org/g/blink-dev/c/6srW418CDgs/m/HWEB0fS5AQAJ
#Development #Techniques
Bluesky likes · Accessible, localizable web components are still a challenge https://ilo.im/164qhh
_____
#WebComponents #Accessibility #Localization #SocialMedia #Content #WebDev #Frontend #HTML #JavaScript #API
Turns out that slotted elements _inherit_ from their slots.
Was about to complain about manual slot assignment in #webcomponents being a chore. But then I noticed that https://www.npmjs.com/package/@sirpepe/ornament already solves all my gripes ¯\_(ツ)_/¯
thanks to a discussion on reddit [1] and some links [2] I came across a different view on #webcomponents.
In short, just wrap content in a #webcomponent instead of trying to "upgrade" it. Like so:
<user-avatar>
<img src>
</user-avatar>
I always thought until now that it should rather be
<img src is=user-avatar>
but `is` is not widely usable.
I still need to digest it. I see the use cases, but somehow feels still strange
[1] https://www.reddit.com/r/HTML/comments/1ldt5s4/spaish_upgrading_the_details_element/
[2] https://adactio.com/journal/20618
I hate saying things which seem blindingly obvious, but when Famous People™ such as Theo on YouTube make these basic mistakes, I wonder.
So here you go:
`document.querySelector("# my-dumb-button").addEventListener(...)` is completely obsolete in the year 2025.
Never do that again please. You don't need to!
If you're wondering “well, what should I do instead?”, check the comments; we'll talk about what to do instead. Apparently it will BLOW YOUR MIND!