From dbfc9ddb5ba66170b0380500a120e8cf5eb0c552 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien?= Date: Thu, 6 Feb 2020 18:48:50 +0100 Subject: [PATCH] fix(carbon-components-react) Updated DataTableCustomSelectionProps accordingly to the Element's props (#42128) * Updated DataTableCustomSelectionProps accordingly to the Element's props * Added test for DataTable * Fixed test lint --- .../carbon-components-react-tests.tsx | 58 +++++++++++++++++++ .../lib/components/DataTable/DataTable.d.ts | 4 +- 2 files changed, 60 insertions(+), 2 deletions(-) diff --git a/types/carbon-components-react/carbon-components-react-tests.tsx b/types/carbon-components-react/carbon-components-react-tests.tsx index db78811a37..87db4e8875 100644 --- a/types/carbon-components-react/carbon-components-react-tests.tsx +++ b/types/carbon-components-react/carbon-components-react-tests.tsx @@ -2,6 +2,7 @@ import * as React from 'react'; import { AccordionItem, DataTable, + DataTableCustomRenderProps, DataTableHeader, DataTableRow, Slider, @@ -169,6 +170,63 @@ const t4 = ( }} /> ); +// RenderProps are compatible with sub-elements +interface T5RowType extends DataTableRow { + col1: number; + col2: number; +} +const t5RowItems: T5RowType[] = [ + { id: "row0", col1: 0, col2: 0}, + { id: "row1", col1: 1, col2: 1}, +]; +const t5Headers: DataTableHeader[] = [ + {key: 'col1', header: 'First column'}, + {key: 'col2', header: 'Second column'} +]; +const t5 = ( + ) => ( + + + + + + {renderProps.headers.map(header => ( + + {header.header} + + ))} + + + + + {renderProps.rows.map(row => ( + + + + {row.cells.map(cell => ( + + {cell.value} + + ))} + + + + ))} + + + + )} + /> +); // UIShell - Link interface TestCompProps { diff --git a/types/carbon-components-react/lib/components/DataTable/DataTable.d.ts b/types/carbon-components-react/lib/components/DataTable/DataTable.d.ts index 22bc4ad88d..7977fb858b 100644 --- a/types/carbon-components-react/lib/components/DataTable/DataTable.d.ts +++ b/types/carbon-components-react/lib/components/DataTable/DataTable.d.ts @@ -70,13 +70,13 @@ export interface DataTableCustomSelectionData { ariaLabel?: string, - checked: R extends never ? boolean : R["isSelected"], + checked: R extends never ? boolean : NonNullable, disabled: R extends never ? never : R["disabled"], id: string, indeterminate: R extends never ? boolean : never, name: string, onSelect(event: React.MouseEvent): void, - radio: R extends never ? never : (Extract | null), + radio?: R extends never ? never : (Extract), } // endregion Row Types