Skip to content

Commit

Permalink
fix(data-table): input name is stable while id is unique (#2088)
Browse files Browse the repository at this point in the history
  • Loading branch information
metonym committed Jan 20, 2025
1 parent 153a28e commit 9d66653
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/DataTable/DataTable.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,8 @@
<InlineCheckbox
bind:ref={refSelectAll}
aria-label="Select all rows"
name="{id}-select-all"
value="all"
checked={selectAll}
{indeterminate}
on:change={(e) => {
Expand Down Expand Up @@ -512,9 +514,12 @@
class:bx--table-column-radio={radio}
>
{#if !nonSelectableRowIds.includes(row.id)}
{@const inputId = `${id}-${row.id}`}
{@const inputName = `${id}-name`}
{#if radio}
<RadioButton
name="{id}-{row.id}"
id={inputId}
name={inputName}
checked={selectedRowIds.includes(row.id)}
on:change={() => {
selectedRowIds = [row.id];
Expand All @@ -523,7 +528,8 @@
/>
{:else}
<InlineCheckbox
name="{id}-{row.id}"
id={inputId}
name={inputName}
checked={selectedRowIds.includes(row.id)}
on:change={() => {
if (selectedRowIds.includes(row.id)) {
Expand Down
3 changes: 3 additions & 0 deletions tests/DataTable/DuplicateDataTables.test.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,6 @@

<DataTable radio {headers} {rows} />
<DataTable radio {headers} {rows} />

<DataTable batchSelection selectable {headers} {rows} />
<DataTable batchSelection selectable {headers} {rows} />

0 comments on commit 9d66653

Please sign in to comment.