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

[EuiPageSection] Fix contentProps not correctly concatenating css #6365

Merged
merged 2 commits into from
Nov 15, 2022
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
24 changes: 24 additions & 0 deletions src/components/page/page_section/page_section.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/

import React from 'react';
import { css } from '@emotion/react';
import { render } from 'enzyme';
import { requiredProps } from '../../../test/required_props';
import { shouldRenderCustomStyles } from '../../../test/internal';
Expand Down Expand Up @@ -109,4 +110,27 @@ describe('EuiPageSection', () => {
});
});
});

// Regression test for recurring bug / unintuitive Emotion behavior
it('correctly merges `css` passed to `contentProps`', () => {
const component = render(
<EuiPageSection
contentProps={{
css: css`
color: red;
`,
'data-test-subj': 'content',
}}
/>
);
const content = component.find('[data-test-subj="content"]');
expect(content).toMatchInlineSnapshot(`
<div
class="emotion-euiPageSection__content-l-css"
data-test-subj="content"
/>
`);
expect(content.attr('class')).toContain('euiPageSection__content'); // Preserves our CSS
expect(content.attr('class').endsWith('-css')).toBeTruthy(); // Concatenates custom CSS
});
});
6 changes: 5 additions & 1 deletion src/components/page/page_section/page_section.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,15 @@ export const EuiPageSection: FunctionComponent<EuiPageSectionProps> = ({
bottomBorder === true && styles.border,
alignment.toLowerCase().includes('center') && contentStyles.center,
restrictWidth && contentStyles.restrictWidth,
contentProps?.css && contentProps.css,
];

return (
<Component css={cssStyles} {...rest}>
<div css={cssContentStyles} {...contentProps} style={widthStyles}>
{/* `css` must be merged manually after props spread on the content wrapper -
Emotion does not automatically correctly merge `css` on non-component JSX */}
{/* eslint-disable-next-line local/css_before_spread_props */}
<div {...contentProps} css={cssContentStyles} style={widthStyles}>
{children}
</div>
</Component>
Expand Down
3 changes: 3 additions & 0 deletions upcoming_changelogs/6365.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
**Bug fixes**

- Re-fixed `EuiPageSection` not correctly merging `contentProps.css`