Skip to content
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`