Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge EuiTableRowCell's childClasses into any existing className #709

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
- Added `EuiEmptyPrompt` which can be used as a placeholder over empty tables and lists ([#711](https://github.com/elastic/eui/pull/711))
- Added `EuiTabbedContent` ([#737](https://github.com/elastic/eui/pull/737))

**Bug fixes**
- Fixed `EuiTableRowCell` from overwriting its child element's `className` [#709](https://github.com/elastic/eui/pull/709)

## [`0.0.44`](https://github.com/elastic/eui/tree/v0.0.44)

- Reduced `EuiToast` title size ([#703](https://github.com/elastic/eui/pull/703))
Expand Down
14 changes: 14 additions & 0 deletions src/components/table/__snapshots__/table_row_cell.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,20 @@ exports[`align renders right when specified 1`] = `
</td>
`;

exports[`children's className merges new classnames into existing ones 1`] = `
<td
class="euiTableRowCell"
>
<div
class="euiTableCellContent euiTableCellContent--showOnHover euiTableCellContent--overflowingContent"
>
<div
class="testClass euiTableCellContent__hoverItem"
/>
</div>
</td>
`;

exports[`renders EuiTableRowCell 1`] = `
<td
class="euiTableRowCell"
Expand Down
8 changes: 7 additions & 1 deletion src/components/table/table_row_cell.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,13 @@ export const EuiTableRowCell = ({
if(textOnly === true) {
modifiedChildren = <span className={childClasses}>{children}</span>;
} else if(React.isValidElement(modifiedChildren)) {
modifiedChildren = React.Children.map(children, child => React.cloneElement(child, { className: childClasses }));
modifiedChildren = React.Children.map(
children,
child => React.cloneElement(
child,
{ className: classNames(child.props.className, childClasses) }
)
);
}

return (
Expand Down
12 changes: 12 additions & 0 deletions src/components/table/table_row_cell.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,15 @@ describe('truncateText', () => {
expect(render(component)).toMatchSnapshot();
});
});

describe(`children's className`, () => {
test('merges new classnames into existing ones', () => {
const component = (
<EuiTableRowCell textOnly={false} showOnHover={true}>
<div className="testClass"/>
</EuiTableRowCell>
);

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