From 67a1fc7037ba86277b7512fc3cd3e3fd33744c43 Mon Sep 17 00:00:00 2001 From: Anish Aggarwal Date: Wed, 26 Feb 2020 22:48:50 +0530 Subject: [PATCH] used single component --- CHANGELOG.md | 2 +- .../__snapshots__/table_header.test.tsx.snap | 10 +++++++ .../table_header_cell.test.tsx.snap | 12 ++++---- src/components/table/table_header.test.tsx | 6 ++++ src/components/table/table_header_cell.tsx | 30 +++++++------------ 5 files changed, 34 insertions(+), 26 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 39d2371c1ee..23f75367b52 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ ## [`master`](https://github.com/elastic/eui/tree/master) -- Empty table th elements replaced with td in `EuiTable`. ([#2873](https://github.com/elastic/eui/pull/2873)) +- Empty table th elements replaced with td in `EuiTable`. ([#2934](https://github.com/elastic/eui/pull/2934)) - Added SASS variables for text variants of the primary palette `$euiColorPrimaryText`, `$euiColorSecondaryText`, etc... Updated components to use these new variables. ([#2873](https://github.com/elastic/eui/pull/2873)) - Updated SASS mixin `makeHighContrastColor()` to default `$background: $euiPageBackgroundColor` and `$ratio: 4.5`. Created `makeGraphicContrastColor()` for graphic specific contrast levels of 3.0. ([#2873](https://github.com/elastic/eui/pull/2873)) diff --git a/src/components/table/__snapshots__/table_header.test.tsx.snap b/src/components/table/__snapshots__/table_header.test.tsx.snap index 09b2da1459f..23cb8bc2282 100644 --- a/src/components/table/__snapshots__/table_header.test.tsx.snap +++ b/src/components/table/__snapshots__/table_header.test.tsx.snap @@ -12,3 +12,13 @@ Array [ "children", ] `; + +exports[`EuiTableHeader renders td when children is null/undefined 1`] = ` + + + +`; diff --git a/src/components/table/__snapshots__/table_header_cell.test.tsx.snap b/src/components/table/__snapshots__/table_header_cell.test.tsx.snap index b6a4321e000..2e35c59f129 100644 --- a/src/components/table/__snapshots__/table_header_cell.test.tsx.snap +++ b/src/components/table/__snapshots__/table_header_cell.test.tsx.snap @@ -1,7 +1,7 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`align defaults to left 1`] = ` - - + `; exports[`align renders center when specified 1`] = ` - - + `; exports[`align renders right when specified 1`] = ` - - + `; exports[`renders EuiTableHeaderCell 1`] = ` diff --git a/src/components/table/table_header.test.tsx b/src/components/table/table_header.test.tsx index f79abcf3827..d9c246d7030 100644 --- a/src/components/table/table_header.test.tsx +++ b/src/components/table/table_header.test.tsx @@ -12,4 +12,10 @@ describe('EuiTableHeader', () => { expect(component).toMatchSnapshot(); }); + + test('renders td when children is null/undefined', () => { + const component = render(); + + expect(component).toMatchSnapshot(); + }); }); diff --git a/src/components/table/table_header_cell.tsx b/src/components/table/table_header_cell.tsx index 48b7dd07796..db0e2dcdb88 100644 --- a/src/components/table/table_header_cell.tsx +++ b/src/components/table/table_header_cell.tsx @@ -91,6 +91,8 @@ export const EuiTableHeaderCell: FunctionComponent = ({ const styleObj = resolveWidthAsStyle(style, width); + const CellComponent = children ? 'th' : 'td'; + if (onSort) { const buttonClasses = classNames('euiTableHeaderButton', { 'euiTableHeaderButton-isSorted': isSorted, @@ -114,7 +116,7 @@ export const EuiTableHeaderCell: FunctionComponent = ({ } return ( - = ({ - - ); - } - - if (children) { - return ( - -
- {children} -
- + ); } return ( - +
{children}
- +
); };