Shadow DOM: <sv-grid-shadow>

Two elements ship, and which one you want is a styling decision:

Element Renders in Page CSS Use when
<sv-grid> the light DOM applies normally Almost always - a data grid usually wants to inherit your app's theme.
<sv-grid-shadow> an open shadow root cannot reach the grid You are embedding in a page whose CSS you do not control, or shipping into someone else's site.

They are two elements rather than one with a shadow attribute because Svelte's customElement.shadow is resolved when the component is COMPILED. No runtime flag can switch it, so no attribute can either.

<script type="module" src="https://unpkg.com/@svgrid/grid-wc/dist/shadow/sv-grid-shadow-element.js"></script>

<sv-grid-shadow id="grid" sortable filterable style="display:block;height:420px"></sv-grid-shadow>
<script type="module">
  const grid = document.getElementById('grid')
  grid.columns = [{ field: 'name', header: 'Name' }, { field: 'city', header: 'City' }]
  grid.data = [{ name: 'Ada', city: 'London' }, { name: 'Linus', city: 'Helsinki' }]
</script>

Everything else is identical: the same 98 properties, the same 72 attributes, the same 20 events. Events are dispatched composed: true, so addEventListener on the host works exactly as it does on <sv-grid>.

What the shadow root does and does not isolate

Theming with --sg-* tokens, which reach into the shadow root by inheritance.

Open the live example: Custom cells + themes (Rows & Cells)

The root is open, never closed. A closed root leaves el.shadowRoot null, which would stop you styling, querying, or testing your own grid - so it is not offered.

Isolation is one-directional, and worth being precise about:

Theming

--sg-* tokens work in both elements, unchanged:

sv-grid, sv-grid-shadow {
  --sg-bg: #fff;
  --sg-header-bg: #f8fafc;
}

A theme stylesheet works too, including its dark variant, even though its selectors are :root and :root[data-theme='dark'] and neither can MATCH inside a shadow tree. Custom properties are inherited properties, and inheritance crosses a shadow boundary - so the values land on the host and are inherited by everything in the root. Verified in a browser rather than reasoned about: it was assumed to be broken for a while, and it is not.

Constraints

Selection, clipboard and the menus that portal out of the root - all identical inside a shadow tree.

Open the live example: Selection + copy/paste (Selection & Clipboard)

See also

Live examples