From 41fc7f755b64f8806544ee54b5b74818eb0645e0 Mon Sep 17 00:00:00 2001 From: Andre Paul Date: Thu, 13 May 2021 15:54:28 -0700 Subject: [PATCH 1/2] added an additional condition for when we would like to expose the column width to child component --- src/components/DataTable/DataTable.tsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/components/DataTable/DataTable.tsx b/src/components/DataTable/DataTable.tsx index 8ba893747..2266b7de0 100644 --- a/src/components/DataTable/DataTable.tsx +++ b/src/components/DataTable/DataTable.tsx @@ -456,7 +456,11 @@ export const DataTable = (props: IDataTableProps) => { } truncateContent={truncateContent} > - {isEmpty ? emptyCellText : cellValue} + {isEmpty + ? emptyCellText + : _.isFunction(cellValue) + ? cellValue(columnProps.width) + : cellValue} ); } From 35b76db3d92e6d22ac49d0452d10b2d2c75b2ab1 Mon Sep 17 00:00:00 2001 From: Andre Paul Date: Fri, 14 May 2021 14:08:58 -0700 Subject: [PATCH 2/2] added test that width is passed along successfully --- src/components/DataTable/DataTable.spec.tsx | 30 +++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/components/DataTable/DataTable.spec.tsx b/src/components/DataTable/DataTable.spec.tsx index 9f6981d73..2a38cd682 100644 --- a/src/components/DataTable/DataTable.spec.tsx +++ b/src/components/DataTable/DataTable.spec.tsx @@ -1045,5 +1045,35 @@ describe('DataTable', () => { ); }); }); + + describe('cellValue is a function', () => { + it('should pass column width as a prop to cellValue', () => { + const testDataWithFunctionInCellValue: any = [ + { + id: 1, + first_name: 'Isaac', + email: 'inewton@example.com', + occupation: 'Physicist', + isDisabled: true, + isSelected: true, + isActive: true, + status: (width) => , + }, + ]; + + const wrapper = mount( + + + + + + + + + ); + + expect(wrapper.find(Checkbox).props()).toHaveProperty('width'); + }); + }); }); });