Skip to content

Commit

Permalink
[EuiPageSection] Fix contentProps not correctly concatenating css (
Browse files Browse the repository at this point in the history
…#6365)

* [EuiPageSection] Fix `contentProps` not correctly concatenating passed cssProps

* changelog
  • Loading branch information
Constance authored Nov 15, 2022
1 parent 2e657f4 commit 0beb4e6
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
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`

0 comments on commit 0beb4e6

Please sign in to comment.