Skip to content

Commit 7010497

Browse files
authored
fix(breadcrumb): temp fix for spacing (#4368)
* fix(breadcrumb): temp fix for spacing * update page snapshot
1 parent ca2e2df commit 7010497

File tree

8 files changed

+112
-170
lines changed

8 files changed

+112
-170
lines changed

packages/react-core/src/components/Breadcrumb/Breadcrumb.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,15 @@ export const Breadcrumb: React.FunctionComponent<BreadcrumbProps & OUIAProps> =
2525
className={css(styles.breadcrumb, className)}
2626
{...getOUIAProps('Breadcrumb', ouiaId)}
2727
>
28-
<ol className={css(styles.breadcrumbList)}>{children}</ol>
28+
<ol className={styles.breadcrumbList}>
29+
{React.Children.map(children, (child, index) => {
30+
const showDivider = index > 0;
31+
if (React.isValidElement(child)) {
32+
return React.cloneElement(child, { showDivider });
33+
}
34+
35+
return child;
36+
})}
37+
</ol>
2938
</nav>
3039
);

packages/react-core/src/components/Breadcrumb/BreadcrumbHeading.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as React from 'react';
2+
import AngleRightIcon from '@patternfly/react-icons/dist/js/icons/angle-right-icon';
23
import styles from '@patternfly/react-styles/css/components/Breadcrumb/breadcrumb';
34
import { css } from '@patternfly/react-styles';
45

@@ -13,6 +14,8 @@ export interface BreadcrumbHeadingProps extends React.HTMLProps<HTMLLIElement> {
1314
target?: string;
1415
/** Sets the base component to render. Defaults to <a> */
1516
component?: React.ReactNode;
17+
/** Internal prop set by Breadcrumb on all but the first crumb */
18+
showDivider?: boolean;
1619
}
1720

1821
export const BreadcrumbHeading: React.FunctionComponent<BreadcrumbHeadingProps> = ({
@@ -21,12 +24,18 @@ export const BreadcrumbHeading: React.FunctionComponent<BreadcrumbHeadingProps>
2124
to = null,
2225
target = null,
2326
component = 'a',
27+
showDivider,
2428
...props
2529
}: BreadcrumbHeadingProps) => {
2630
const Component = component as any;
2731
return (
2832
<li {...props} className={css(styles.breadcrumbItem, className)}>
29-
<h1 className={css(styles.breadcrumbHeading)}>
33+
<h1 className={styles.breadcrumbHeading}>
34+
{showDivider && (
35+
<span className={styles.breadcrumbItemDivider}>
36+
<AngleRightIcon />
37+
</span>
38+
)}
3039
{to && (
3140
<Component
3241
href={to}

packages/react-core/src/components/Breadcrumb/BreadcrumbItem.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ export interface BreadcrumbItemProps extends React.HTMLProps<HTMLLIElement> {
1212
to?: string;
1313
/** Flag indicating whether the item is active. */
1414
isActive?: boolean;
15+
/** Internal prop set by Breadcrumb on all but the first crumb */
16+
showDivider?: boolean;
1517
/** Target for breadcrumb link. */
1618
target?: string;
1719
/** Sets the base component to render. Defaults to <a> */
@@ -23,13 +25,19 @@ export const BreadcrumbItem: React.FunctionComponent<BreadcrumbItemProps> = ({
2325
className = '',
2426
to = null,
2527
isActive = false,
28+
showDivider,
2629
target = null,
2730
component = 'a',
2831
...props
2932
}: BreadcrumbItemProps) => {
3033
const Component = component;
3134
return (
3235
<li {...props} className={css(styles.breadcrumbItem, className)}>
36+
{showDivider && (
37+
<span className={styles.breadcrumbItemDivider}>
38+
<AngleRightIcon />
39+
</span>
40+
)}
3341
{to && (
3442
<Component
3543
href={to}
@@ -41,11 +49,6 @@ export const BreadcrumbItem: React.FunctionComponent<BreadcrumbItemProps> = ({
4149
</Component>
4250
)}
4351
{!to && <React.Fragment>{children}</React.Fragment>}
44-
{!isActive && (
45-
<span className={css(styles.breadcrumbItemDivider)}>
46-
<AngleRightIcon />
47-
</span>
48-
)}
4952
</li>
5053
);
5154
};

packages/react-core/src/components/Breadcrumb/__tests__/Generated/__snapshots__/BreadcrumbItem.test.tsx.snap

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,5 @@ exports[`BreadcrumbItem should match snapshot (auto-generated) 1`] = `
1111
>
1212
ReactNode
1313
</a>
14-
<span
15-
className="pf-c-breadcrumb__item-divider"
16-
>
17-
<AngleRightIcon
18-
color="currentColor"
19-
noVerticalAlign={false}
20-
size="sm"
21-
/>
22-
</span>
2314
</li>
2415
`;

packages/react-core/src/components/Breadcrumb/__tests__/__snapshots__/Breadcrumb.test.tsx.snap

Lines changed: 11 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ exports[`Breadcrumb component should render breadcrumb with children 1`] = `
3131
className="pf-c-breadcrumb__list"
3232
>
3333
<BreadcrumbItem
34+
key=".0"
35+
showDivider={false}
3436
to="#"
3537
>
3638
<li
@@ -43,51 +45,17 @@ exports[`Breadcrumb component should render breadcrumb with children 1`] = `
4345
>
4446
Item 1
4547
</a>
46-
<span
47-
className="pf-c-breadcrumb__item-divider"
48-
>
49-
<AngleRightIcon
50-
color="currentColor"
51-
noVerticalAlign={false}
52-
size="sm"
53-
>
54-
<svg
55-
aria-hidden={true}
56-
aria-labelledby={null}
57-
fill="currentColor"
58-
height="1em"
59-
role="img"
60-
style={
61-
Object {
62-
"verticalAlign": "-0.125em",
63-
}
64-
}
65-
viewBox="0 0 256 512"
66-
width="1em"
67-
>
68-
<path
69-
d="M224.3 273l-136 136c-9.4 9.4-24.6 9.4-33.9 0l-22.6-22.6c-9.4-9.4-9.4-24.6 0-33.9l96.4-96.4-96.4-96.4c-9.4-9.4-9.4-24.6 0-33.9L54.3 103c9.4-9.4 24.6-9.4 33.9 0l136 136c9.5 9.4 9.5 24.6.1 34z"
70-
transform=""
71-
/>
72-
</svg>
73-
</AngleRightIcon>
74-
</span>
7548
</li>
7649
</BreadcrumbItem>
7750
7851
<BreadcrumbItem
52+
key=".2"
53+
showDivider={true}
7954
to="#"
8055
>
8156
<li
8257
className="pf-c-breadcrumb__item"
8358
>
84-
<a
85-
className="pf-c-breadcrumb__link"
86-
href="#"
87-
target={null}
88-
>
89-
Item 1
90-
</a>
9159
<span
9260
className="pf-c-breadcrumb__item-divider"
9361
>
@@ -117,6 +85,13 @@ exports[`Breadcrumb component should render breadcrumb with children 1`] = `
11785
</svg>
11886
</AngleRightIcon>
11987
</span>
88+
<a
89+
className="pf-c-breadcrumb__link"
90+
href="#"
91+
target={null}
92+
>
93+
Item 1
94+
</a>
12095
</li>
12196
</BreadcrumbItem>
12297
</ol>

packages/react-core/src/components/Breadcrumb/__tests__/__snapshots__/BreadcrumbItem.test.tsx.snap

Lines changed: 0 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,6 @@ exports[`BreadcrumbItem component should render breadcrumbItem with className 1`
1313
className="pf-c-breadcrumb__item Class"
1414
>
1515
Item
16-
<span
17-
className="pf-c-breadcrumb__item-divider"
18-
>
19-
<AngleRightIcon
20-
color="currentColor"
21-
noVerticalAlign={false}
22-
size="sm"
23-
/>
24-
</span>
2516
</li>
2617
`;
2718

@@ -30,15 +21,6 @@ exports[`BreadcrumbItem component should render breadcrumbItem with component 1`
3021
className="pf-c-breadcrumb__item"
3122
>
3223
Stuff
33-
<span
34-
className="pf-c-breadcrumb__item-divider"
35-
>
36-
<AngleRightIcon
37-
color="currentColor"
38-
noVerticalAlign={false}
39-
size="sm"
40-
/>
41-
</span>
4224
</li>
4325
`;
4426

@@ -49,15 +31,6 @@ exports[`BreadcrumbItem component should render breadcrumbItem with custom eleme
4931
<h1>
5032
Header
5133
</h1>
52-
<span
53-
className="pf-c-breadcrumb__item-divider"
54-
>
55-
<AngleRightIcon
56-
color="currentColor"
57-
noVerticalAlign={false}
58-
size="sm"
59-
/>
60-
</span>
6134
</li>
6235
`;
6336

@@ -67,15 +40,6 @@ exports[`BreadcrumbItem component should render breadcrumbItem with id 1`] = `
6740
id="Item 1"
6841
>
6942
Item
70-
<span
71-
className="pf-c-breadcrumb__item-divider"
72-
>
73-
<AngleRightIcon
74-
color="currentColor"
75-
noVerticalAlign={false}
76-
size="sm"
77-
/>
78-
</span>
7943
</li>
8044
`;
8145

@@ -84,15 +48,6 @@ exports[`BreadcrumbItem component should render breadcrumbItem with target 1`] =
8448
className="pf-c-breadcrumb__item"
8549
>
8650
Item
87-
<span
88-
className="pf-c-breadcrumb__item-divider"
89-
>
90-
<AngleRightIcon
91-
color="currentColor"
92-
noVerticalAlign={false}
93-
size="sm"
94-
/>
95-
</span>
9651
</li>
9752
`;
9853

@@ -101,15 +56,6 @@ exports[`BreadcrumbItem component should render default breadcrumbItem 1`] = `
10156
className="pf-c-breadcrumb__item"
10257
>
10358
Item
104-
<span
105-
className="pf-c-breadcrumb__item-divider"
106-
>
107-
<AngleRightIcon
108-
color="currentColor"
109-
noVerticalAlign={false}
110-
size="sm"
111-
/>
112-
</span>
11359
</li>
11460
`;
11561

@@ -124,14 +70,5 @@ exports[`BreadcrumbItem component should render link breadcrumbItem 1`] = `
12470
>
12571
Item
12672
</a>
127-
<span
128-
className="pf-c-breadcrumb__item-divider"
129-
>
130-
<AngleRightIcon
131-
color="currentColor"
132-
noVerticalAlign={false}
133-
size="sm"
134-
/>
135-
</span>
13673
</li>
13774
`;

0 commit comments

Comments
 (0)