mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-14 18:01:06 +00:00
fix(data-table): prefix internal ID for radio button, checkbox (#2082)
Fixes #2081
This commit is contained in:
parent
f3a8d9972c
commit
eb1567ac1b
3 changed files with 28 additions and 2 deletions
|
@ -170,6 +170,10 @@
|
|||
const batchSelectedIds = writable(false);
|
||||
const tableRows = writable(rows);
|
||||
|
||||
// Internal ID prefix for radio buttons, checkboxes, etc.
|
||||
// since there may be multiple `DataTable` instances that have overlapping row ids.
|
||||
const id = "ccs-" + Math.random().toString(36);
|
||||
|
||||
// Store a copy of the original rows for filter restoration.
|
||||
$: originalRows = [...rows];
|
||||
|
||||
|
@ -499,7 +503,7 @@
|
|||
{#if !nonSelectableRowIds.includes(row.id)}
|
||||
{#if radio}
|
||||
<RadioButton
|
||||
name="select-row-{row.id}"
|
||||
name="{id}-{row.id}"
|
||||
checked={selectedRowIds.includes(row.id)}
|
||||
on:change={() => {
|
||||
selectedRowIds = [row.id];
|
||||
|
@ -508,7 +512,7 @@
|
|||
/>
|
||||
{:else}
|
||||
<InlineCheckbox
|
||||
name="select-row-{row.id}"
|
||||
name="{id}-{row.id}"
|
||||
checked={selectedRowIds.includes(row.id)}
|
||||
on:change={() => {
|
||||
if (selectedRowIds.includes(row.id)) {
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
import Accordion from "./Accordion/Accordion.test.svelte";
|
||||
import AccordionProgrammatic from "./Accordion/Accordion.programmatic.test.svelte";
|
||||
import AccordionDisabled from "./Accordion/Accordion.disabled.test.svelte";
|
||||
import DuplicateDataTables from "./DataTable/DuplicateDataTables.test.svelte";
|
||||
import TreeView from "./TreeView/TreeView.test.svelte";
|
||||
import TreeViewHierarchy from "./TreeView/TreeView.hierarchy.test.svelte";
|
||||
import RecursiveList from "./RecursiveList/RecursiveList.test.svelte";
|
||||
|
@ -32,6 +33,11 @@
|
|||
name: "AccordionDisabled",
|
||||
component: AccordionDisabled,
|
||||
},
|
||||
{
|
||||
path: "/data-table",
|
||||
name: "DataTable",
|
||||
component: DuplicateDataTables,
|
||||
},
|
||||
{
|
||||
path: "/recursive-list",
|
||||
name: "RecursiveList",
|
||||
|
|
16
tests/DataTable/DuplicateDataTables.test.svelte
Normal file
16
tests/DataTable/DuplicateDataTables.test.svelte
Normal file
|
@ -0,0 +1,16 @@
|
|||
<script lang="ts">
|
||||
import { DataTable } from "carbon-components-svelte";
|
||||
|
||||
const headers = [
|
||||
{ key: "id", value: "id" },
|
||||
{ key: "contact.company", value: "Company name" },
|
||||
] as const;
|
||||
|
||||
const rows = [
|
||||
{ id: "1", contact: { company: "Company 1" } },
|
||||
{ id: "2", contact: { company: "Company 2" } },
|
||||
];
|
||||
</script>
|
||||
|
||||
<DataTable radio {headers} {rows} />
|
||||
<DataTable radio {headers} {rows} />
|
Loading…
Add table
Add a link
Reference in a new issue