html-traits
A JavaScript/HTML library that adds behaviors to existing HTML elements via a `traits` attribute instead of the web components `is` attribute. Designed for progressive enhancement: elements keep working when JavaScript is disabled or broken, and gain behaviors when JS runs—for example an `expando` trait that makes a textarea auto-expand, or a `character-limit` trait with a `data-character-limit="200"` attribute that turns the box red past a threshold. Behaviors compose as plain attributes on the element, avoiding nested web component markup and shadow-DOM reimplementation of native element behavior.
What it addresses
Normal web components lead to nested element markup or hide the original element in the shadow DOM, forcing developers to reimplement native behavior; and elements break entirely when JavaScript fails or is disabled.
Shared over time
Each entry reflects what was shared on that date. Details may have changed since then.
html-traits
A JavaScript/HTML library that adds behaviors to existing HTML elements via a `traits` attribute instead of the web components `is` attribute. Designed for progressive enhancement: elements keep working when JavaScript is disabled or broken, and gain behaviors when JS runs—for example an `expando` trait that makes a textarea auto-expand, or a `character-limit` trait with a `data-character-limit="200"` attribute that turns the box red past a threshold. Behaviors compose as plain attributes on the element, avoiding nested web component markup and shadow-DOM reimplementation of native element behavior.
Problem: Normal web components lead to nested element markup or hide the original element in the shadow DOM, forcing developers to reimplement native behavior; and elements break entirely when JavaScript fails or is disabled.
Audience: Developers building web pages with HTML/JavaScript
Posted by @nymanjon · Original source ↗
Source text · @nymanjon · · Source ↗
I built a simple lib for JS/HTML called html-traits[1]. It's similar to built-in web components but instead of using the `is` attribute you use the `traits` attribute. So, it is specifically meant for progressive enhancement.