Skip to content

Commit d341d0b

Browse files
authored
feat(card): add hasHeaderWrap prop and test to support card header wrapping (#11663)
* feat(card): add hasHeaderWrap prop and test to support card header wrapping * feat(card): use hasWrap to enable header elements to wrap and changes to tests
1 parent debf928 commit d341d0b

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

packages/react-core/src/components/Card/CardHeader.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ export interface CardHeaderProps extends React.HTMLProps<HTMLDivElement> {
7575
toggleButtonProps?: any;
7676
/** Whether to right-align expandable toggle button */
7777
isToggleRightAligned?: boolean;
78+
/** Flag indicating that header wrapping is enabled */
79+
hasWrap?: boolean;
7880
}
7981

8082
export const CardHeader: React.FunctionComponent<CardHeaderProps> = ({
@@ -86,6 +88,7 @@ export const CardHeader: React.FunctionComponent<CardHeaderProps> = ({
8688
onExpand,
8789
toggleButtonProps,
8890
isToggleRightAligned,
91+
hasWrap,
8992
...props
9093
}: CardHeaderProps) => (
9194
<GenerateId>
@@ -177,7 +180,12 @@ export const CardHeader: React.FunctionComponent<CardHeaderProps> = ({
177180

178181
return (
179182
<div
180-
className={css(styles.cardHeader, isToggleRightAligned && styles.modifiers.toggleRight, className)}
183+
className={css(
184+
styles.cardHeader,
185+
isToggleRightAligned && styles.modifiers.toggleRight,
186+
hasWrap && styles.modifiers.wrap,
187+
className
188+
)}
181189
id={id}
182190
{...props}
183191
>

packages/react-core/src/components/Card/__tests__/CardHeader.test.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import { render, screen } from '@testing-library/react';
2+
import styles from '@patternfly/react-styles/css/components/Card/card';
3+
import '@testing-library/jest-dom';
24
import userEvent from '@testing-library/user-event';
35
import { CardHeader } from '../CardHeader';
46
import { CardContext } from '../Card';
@@ -13,6 +15,18 @@ describe('CardHeader', () => {
1315
const { asFragment } = render(<CardHeader actions="test" />);
1416
expect(asFragment()).toMatchSnapshot();
1517
});
18+
19+
test(`Should render CardHeader without ${styles.modifiers.wrap} by default`, () => {
20+
render(<CardHeader data-testid="card-header" />);
21+
22+
expect(screen.getByTestId('card-header')).not.toHaveClass(styles.modifiers.wrap);
23+
});
24+
25+
test(`Should render CardHeader with ${styles.modifiers.wrap} class when hasWrap is true`, () => {
26+
render(<CardHeader data-testid="card-header-will-wrap" hasWrap />);
27+
28+
expect(screen.getByTestId('card-header-will-wrap')).toHaveClass(styles.modifiers.wrap);
29+
});
1630
});
1731

1832
// TODO: check if hasNoOffset for actions/selectableActions and className for selectableActions render

0 commit comments

Comments
 (0)