Web components don't need a constructor() | Go Make Things
For years, I’ve written my web component classes with a constructor() method that calls super() to get access to the parent HTMLElement class’s properties…
customElements.define('my-awesome-web-component', class extends HTMLElement { constructor () { // Inherit properties super(); // The rest of your code... } }); For my demo projects, I often do all the things in the constructor().
But with Kelp, my UI library for people who love HTML, I’m initializing my in the connectedCallback() method.
Today, I wanted to talk about the “right” way to load web components to ensure they work predictably every time. Let’s dig in!
The challenge Web components are self instantiating.
Let’s imagine you’re creating a table of contents. When you use a traditional JavaScript library, you explicitly instantiate the library on a specific element.
div id="toc"/divconst myTOC = new TableOfContents('#toc'); But with web components, all you need to do is include the custom element associated with the component.
Progressively enhancing forms with an HTML Web Component (part 1)
Yesterday, I gave an overview of how I approach adding dynamic content to a static, server-rendered website.
Today, we’re going to dig into one piece of that puzzle: ajaxy forms. Let’s dig in!
Forms FTW! Forms are awesome! With an HTML form, you can support JavaScript-free user iterations.
For example, let’s say I want to let users add an item to a list. I can include a form element with a field to add a new item.
"Web Components" is an umbrella term for three main technologies: Custom elements, shadow DOM and HTML templates. Using these technologies allows us to create reusable, optionally encapsulated components. There are some important caveats regarding accessibility we need to keep in mind when authoring web components.
Liskov's Gun: The parallel evolution of React and Web Components
Because this essay is over 11 000 words long(!) I’ve made a convenience EPUB file for offline reading. (EPUB only! No PDF this time.) You can download it over on the fulfilment service I use, Lemon Squeezy, with the option to pay what you want if you feel the urge to support my writing.
Over the weekend, Remy Sharp asked…
Are we at all worried, or even wary, of web component name collisions?
The concern here is that if you have a custom element named toggle-tabs, and then important another Web Component that also uses that same custom element name, you’ve now introduced a collision.
In the ES import-based JavaScript world, having two functions with the same name isn’t that big of a deal because…
Web Components and You (part 10): Provider patterns - Jschof.dev
Web components are by default pretty isolated. There are some nice patterns to start sharing state and actions among web components. This article explores the 'provider' pattern