File tree Expand file tree Collapse file tree 3 files changed +37
-2
lines changed Expand file tree Collapse file tree 3 files changed +37
-2
lines changed Original file line number Diff line number Diff line change 170170 const batchSelectedIds = writable (false );
171171 const tableRows = writable (rows);
172172
173+ // Internal ID prefix for radio buttons, checkboxes, etc.
174+ // since there may be multiple `DataTable` instances that have overlapping row ids.
175+ const id = " ccs-" + Math .random ().toString (36 );
176+
173177 // Store a copy of the original rows for filter restoration.
174178 $: originalRows = [... rows];
175179
370374 < InlineCheckbox
371375 bind: ref= {refSelectAll}
372376 aria- label= " Select all rows"
377+ name= " {id}-select-all"
378+ value= " all"
373379 checked= {selectAll}
374380 {indeterminate}
375381 on: change= {(e ) => {
497503 class: bx-- table- column- radio= {radio}
498504 >
499505 {#if ! nonSelectableRowIds .includes (row .id )}
506+ {@const inputId = ` ${ id} -${ row .id } ` }
507+ {@const inputName = ` ${ id} -name` }
500508 {#if radio}
501509 < RadioButton
502- name= " select-row-{row.id}"
510+ id= {inputId}
511+ name= {inputName}
503512 checked= {selectedRowIds .includes (row .id )}
504513 on: change= {() => {
505514 selectedRowIds = [row .id ];
508517 / >
509518 {: else }
510519 < InlineCheckbox
511- name= " select-row-{row.id}"
520+ id= {inputId}
521+ name= {inputName}
512522 checked= {selectedRowIds .includes (row .id )}
513523 on: change= {() => {
514524 if (selectedRowIds .includes (row .id )) {
Original file line number Diff line number Diff line change 44 import Accordion from " ./Accordion/Accordion.test.svelte" ;
55 import AccordionProgrammatic from " ./Accordion/Accordion.programmatic.test.svelte" ;
66 import AccordionDisabled from " ./Accordion/Accordion.disabled.test.svelte" ;
7+ import DuplicateDataTables from " ./DataTable/DuplicateDataTables.test.svelte" ;
78 import TreeView from " ./TreeView/TreeView.test.svelte" ;
89 import TreeViewHierarchy from " ./TreeView/TreeView.hierarchy.test.svelte" ;
910 import RecursiveList from " ./RecursiveList/RecursiveList.test.svelte" ;
3233 name: " AccordionDisabled" ,
3334 component: AccordionDisabled ,
3435 },
36+ {
37+ path: " /data-table" ,
38+ name: " DataTable" ,
39+ component: DuplicateDataTables ,
40+ },
3541 {
3642 path: " /recursive-list" ,
3743 name: " RecursiveList" ,
Original file line number Diff line number Diff line change 1+ <script lang =" ts" >
2+ import { DataTable } from " carbon-components-svelte" ;
3+
4+ const headers = [
5+ { key: " id" , value: " id" },
6+ { key: " contact.company" , value: " Company name" },
7+ ] as const ;
8+
9+ const rows = [
10+ { id: " 1" , contact: { company: " Company 1" } },
11+ { id: " 2" , contact: { company: " Company 2" } },
12+ ];
13+ </script >
14+
15+ <DataTable radio {headers } {rows } />
16+ <DataTable radio {headers } {rows } />
17+
18+ <DataTable batchSelection selectable {headers } {rows } />
19+ <DataTable batchSelection selectable {headers } {rows } />
You can’t perform that action at this time.
0 commit comments