Class-only import and manual registration
The class import does not register an element. The captioned table remains readable if JavaScript or the CDN fails; sort buttons appear only after enhancement. At narrow widths, focus the table region and use arrow keys to scroll. Use plain-text headers: enhancement replaces their contents with native buttons.
<script type="module">
import { TableSortableElement } from 'https://esm.sh/@aarongustafson/table-sortable@2.1.5/table-sortable.js?bundle&target=es2022';
if (!customElements.get('table-sortable')) {
customElements.define('table-sortable', TableSortableElement);
}
</script>
<table-sortable tabindex="0" role="region" aria-label="People table">
<table>
<caption>People and cities</caption>
<thead>
<tr><th>Name</th><th>Age</th><th>City</th></tr>
</thead>
<tbody>
<tr><td>Charlie</td><td>35</td><td>New York</td></tr>
<tr><td>Alice</td><td>28</td><td>Boston</td></tr>
<tr><td>Bob</td><td>42</td><td>Chicago</td></tr>
</tbody>
</table>
</table-sortable>
| Name | Age | City |
|---|---|---|
| Charlie | 35 | New York |
| Alice | 28 | Boston |
| Bob | 42 | Chicago |