Skip to content

Commit

Permalink
used single component
Browse files Browse the repository at this point in the history
  • Loading branch information
anishagg17 committed Feb 26, 2020
1 parent 2a4ec83 commit c42e809
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 26 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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))

Expand Down
10 changes: 10 additions & 0 deletions src/components/table/__snapshots__/table_header.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,13 @@ Array [
"children",
]
`;

exports[`EuiTableHeader renders td when children is null/undefined 1`] = `
<thead
aria-label="aria-label"
class="testClass1 testClass2"
data-test-subj="test subject string"
>
<tr />
</thead>
`;
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`align defaults to left 1`] = `
<th
<td
class="euiTableHeaderCell"
role="columnheader"
scope="col"
Expand All @@ -13,11 +13,11 @@ exports[`align defaults to left 1`] = `
class="euiTableCellContent__text"
/>
</div>
</th>
</td>
`;

exports[`align renders center when specified 1`] = `
<th
<td
class="euiTableHeaderCell"
role="columnheader"
scope="col"
Expand All @@ -29,11 +29,11 @@ exports[`align renders center when specified 1`] = `
class="euiTableCellContent__text"
/>
</div>
</th>
</td>
`;

exports[`align renders right when specified 1`] = `
<th
<td
class="euiTableHeaderCell"
role="columnheader"
scope="col"
Expand All @@ -45,7 +45,7 @@ exports[`align renders right when specified 1`] = `
class="euiTableCellContent__text"
/>
</div>
</th>
</td>
`;

exports[`renders EuiTableHeaderCell 1`] = `
Expand Down
6 changes: 6 additions & 0 deletions src/components/table/table_header.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,10 @@ describe('EuiTableHeader', () => {

expect(component).toMatchSnapshot();
});

test('renders td when children is null/undefined', () => {
const component = render(<EuiTableHeader {...requiredProps} />);

expect(component).toMatchSnapshot();
});
});
30 changes: 11 additions & 19 deletions src/components/table/table_header_cell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ export const EuiTableHeaderCell: FunctionComponent<Props> = ({

const styleObj = resolveWidthAsStyle(style, width);

const CellComponent = children == null ? 'td' : 'th';

if (onSort) {
const buttonClasses = classNames('euiTableHeaderButton', {
'euiTableHeaderButton-isSorted': isSorted,
Expand All @@ -114,7 +116,7 @@ export const EuiTableHeaderCell: FunctionComponent<Props> = ({
}

return (
<th
<CellComponent
className={classes}
scope={scope}
role="columnheader"
Expand Down Expand Up @@ -142,30 +144,20 @@ export const EuiTableHeaderCell: FunctionComponent<Props> = ({
</EuiScreenReaderOnly>
</span>
</button>
</th>
);
}

if (children) {
return (
<th
className={classes}
scope={scope}
role="columnheader"
style={styleObj}
{...rest}>
<div className={contentClasses}>
<span className="euiTableCellContent__text">{children}</span>
</div>
</th>
</CellComponent>
);
}

return (
<td className={classes} style={styleObj} {...rest}>
<CellComponent
className={classes}
scope={scope}
role="columnheader"
style={styleObj}
{...rest}>
<div className={contentClasses}>
<span className="euiTableCellContent__text">{children}</span>
</div>
</td>
</CellComponent>
);
};

0 comments on commit c42e809

Please sign in to comment.