Skip to content

Commit

Permalink
Merge EuiTableRowCell's childClasses into any existing classNames, fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
chandlerprall committed Apr 27, 2018
1 parent 016ec92 commit eaabb15
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
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();
});
});

0 comments on commit eaabb15

Please sign in to comment.