Template root
Attribute inheritance
Usage attributes merge onto this root element at build time.
Feature
Any attribute on a component usage tag that is not a Bascik-specific attribute (data-bascik-*) is automatically merged onto the component's root element. This is analogous to Vue's "fallthrough attributes".
When Bascik transpiles a component, it reads the usage tag, extracts any inheritable attributes, and merges them onto the first element of the compiled output. The component template and the usage attributes are combined, classes are appended, all other attributes are forwarded:
<!-- usage in your page HTML -->
<site-nav
class="sticky"
aria-label="main navigation"
data-testid="main-nav">
</site-nav>
<!-- site-nav.html - component template -->
<nav class="nav">
<a href="/">Home</a>
</nav><!-- compiled output -->
<nav
class="bascik__site-nav__nav sticky"
aria-label="main navigation"
data-testid="main-nav">
<a href="/">Home</a>
</nav>When the root element already has a scoped class, the inherited class is appended rather than replacing it.
<!-- root element has scoped class -->
<nav class="bascik__site-nav__nav">...</nav>
<!-- after merging class="sticky" -->
<nav class="bascik__site-nav__nav sticky">...</nav>All attributes on the usage tag are inherited exceptdata-bascik-* attributes, which are consumed by Bascik for slots, props, and build instructions.
Common use cases:
class="sticky", class="hidden"aria-label, role, aria-hiddendata-testid, data-cydata-* attribute except data-bascik-*idid is treated like any other inheritable attribute unless the component root already has its own id.
<!-- usage -->
<brand-logo id="footer-logo"></brand-logo><!-- template root has no id -->
<div class="bascik__brand-logo__logo-wrap">
<img src="/img/logo.svg" alt="Brand logo" />
</div><!-- compiled output - id forwarded from usage tag -->
<div class="bascik__brand-logo__logo-wrap" id="footer-logo">
<img src="/img/logo.svg" alt="Brand logo" />
</div>If the template root already defines an id, Bascik keeps the template's root id and does not overwrite it with the usage-site id. That prevents root-level collisions while still letting you anchor page-level CSS or JavaScript to a component root that does not already declare one.
Practical rule: If page code needs to target a component root by id, put the id on the usage tag only when the component root does not already define one.
Inherited class names are not scoped, they are treated as global classes. This is intentional: you are passing a page-level concern onto the component's root element.
<my-card class="featured">
<p>Featured content</p>
</my-card>The featured class is a global class that you define in your page-level stylesheet, separate from the component's scoped CSS.
Self-closing syntax works too: Attribute inheritance works with both paired and self-closing usage syntax: <my-icon class="large" aria-hidden="true" />
MDN reference. Bascik forwards standard HTML attributes instead of inventing a new API. Use MDN's HTML attribute reference as the primary guide for what each inherited attribute means.
Attribute inheritance is enabled by default. Set inheritAttributes: false in bascik.config.js when you want every component root to be controlled only by its own template:
export const bascikConfig = {
inheritAttributes: false,
};The demo below forwards a class, an accessibility label, and a testing hook onto the component root.
Template root
Usage attributes merge onto this root element at build time.
<inherit-demo-card
class="featured-card"
aria-label="Featured inheritance demo"
data-testid="inherit-demo">
</inherit-demo-card><article class="inherit-card">
<p class="inherit-card-kicker">Template root</p>
<h3 class="inherit-card-title">Attribute inheritance</h3>
<p class="inherit-card-body">Usage attributes merge onto this root element at build time.</p>
</article>.inherit-card {
width: min(100%, 34rem);
background: var(--elevated);
border: 1px solid var(--border);
border-radius: var(--r);
padding: 24px;
}
.inherit-card-kicker {
margin: 0 0 10px;
font-size: 0.72rem;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
color: var(--accent);
}
.inherit-card-title {
margin: 0 0 10px;
font-size: 1.05rem;
}
.inherit-card-body {
margin: 0;
color: var(--text-muted);
}<article
class="bascik__inherit-demo-card__inherit-card featured-card"
aria-label="Featured inheritance demo"
data-testid="inherit-demo">
<p class="bascik__inherit-demo-card__inherit-card-kicker">Template root</p>
<h3 class="bascik__inherit-demo-card__inherit-card-title">Attribute inheritance</h3>
<p class="bascik__inherit-demo-card__inherit-card-body">Usage attributes merge onto this root element at build time.</p>
</article>