Skip to content

Commit 9d66653

Browse files
committed
fix(data-table): input name is stable while id is unique (#2088)
1 parent 153a28e commit 9d66653

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/DataTable/DataTable.svelte

+8-2
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,8 @@
381381
<InlineCheckbox
382382
bind:ref={refSelectAll}
383383
aria-label="Select all rows"
384+
name="{id}-select-all"
385+
value="all"
384386
checked={selectAll}
385387
{indeterminate}
386388
on:change={(e) => {
@@ -512,9 +514,12 @@
512514
class:bx--table-column-radio={radio}
513515
>
514516
{#if !nonSelectableRowIds.includes(row.id)}
517+
{@const inputId = `${id}-${row.id}`}
518+
{@const inputName = `${id}-name`}
515519
{#if radio}
516520
<RadioButton
517-
name="{id}-{row.id}"
521+
id={inputId}
522+
name={inputName}
518523
checked={selectedRowIds.includes(row.id)}
519524
on:change={() => {
520525
selectedRowIds = [row.id];
@@ -523,7 +528,8 @@
523528
/>
524529
{:else}
525530
<InlineCheckbox
526-
name="{id}-{row.id}"
531+
id={inputId}
532+
name={inputName}
527533
checked={selectedRowIds.includes(row.id)}
528534
on:change={() => {
529535
if (selectedRowIds.includes(row.id)) {

tests/DataTable/DuplicateDataTables.test.svelte

+3
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,6 @@
1414

1515
<DataTable radio {headers} {rows} />
1616
<DataTable radio {headers} {rows} />
17+
18+
<DataTable batchSelection selectable {headers} {rows} />
19+
<DataTable batchSelection selectable {headers} {rows} />

0 commit comments

Comments
 (0)