Skip to content

Commit 1fd12b0

Browse files
itwasmattgreggchloerice
authored andcommitted
Deprecate breadcrumbs and allow singular backAction prop on Page and Breadcrumbs (Shopify#8135)
### WHY are these changes introduced? As a followup to Shopify#8016 in preparation for v11 where breadcrumb becomes singular (Shopify#7990). I should have originally done this and deprecated breadcrumbs but at the time we had a different upgrade path in mind. After collaborating with a number of folks we determined deprecating breadcrumbs officially and moving to a singular breadcrumb in a `backAction` prop for v11 was the best path. ### WHAT is this pull request doing? <!-- Summary of the changes committed. Before / after screenshots are appreciated for UI changes. Make sure to include alt text that describes the screenshot. If you include an animated gif showing your change, wrapping it in a details tag is recommended. Gifs usually autoplay, which can cause accessibility issues for people reviewing your PR: <details> <summary>Summary of your gif(s)</summary> <img src="..." alt="Description of what the gif shows"> </details> --> <!-- ℹ️ Delete the following for small / trivial changes --> ### How to 🎩 🖥 [Local development instructions](https://github.com/Shopify/polaris/blob/main/README.md#local-development) 🗒 [General tophatting guidelines](https://github.com/Shopify/polaris/blob/main/documentation/Tophatting.md) 📄 [Changelog guidelines](https://github.com/Shopify/polaris/blob/main/.github/CONTRIBUTING.md#changelog) <!-- Give as much information as needed to experiment with the component in the playground. --> <details> <summary>Copy-paste this code in <code>playground/Playground.tsx</code>:</summary> ```jsx import React from 'react'; import {Page} from '../src'; export function Playground() { return ( <Page title="Playground"> {/* Add the code you want to test in here */} </Page> ); } ``` </details> ### 🎩 checklist - [ ] Tested on [mobile](https://github.com/Shopify/polaris/blob/main/documentation/Tophatting.md#cross-browser-testing) - [ ] Tested on [multiple browsers](https://help.shopify.com/en/manual/shopify-admin/supported-browsers) - [ ] Tested for [accessibility](https://github.com/Shopify/polaris/blob/main/documentation/Accessibility%20testing.md) - [ ] Updated the component's `README.md` with documentation changes - [ ] [Tophatted documentation](https://github.com/Shopify/polaris/blob/main/documentation/Tophatting%20documentation.md) changes in the style guide --------- Co-authored-by: Chloe Rice <chloerice@users.noreply.github.com>
1 parent 5877678 commit 1fd12b0

File tree

5 files changed

+71
-11
lines changed

5 files changed

+71
-11
lines changed

.changeset/metal-cows-poke.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@shopify/polaris': minor
3+
---
4+
5+
Deprecated the `Page` `breadcrumbs` prop in favor of the new `backAction` prop.

polaris-react/src/components/Breadcrumbs/Breadcrumbs.tsx

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,25 @@ import {Text} from '../Text';
1010
import styles from './Breadcrumbs.scss';
1111

1212
export interface BreadcrumbsProps {
13-
/** Collection of breadcrumbs */
14-
breadcrumbs: (CallbackAction | LinkAction) | (CallbackAction | LinkAction)[];
13+
/** @deprecated Collection of breadcrumbs */
14+
breadcrumbs?: (CallbackAction | LinkAction) | (CallbackAction | LinkAction)[];
15+
/** Back action link */
16+
backAction?: CallbackAction | LinkAction;
1517
}
1618

17-
export function Breadcrumbs({breadcrumbs}: BreadcrumbsProps) {
18-
const breadcrumb = Array.isArray(breadcrumbs)
19-
? breadcrumbs[breadcrumbs.length - 1]
20-
: breadcrumbs;
19+
export function Breadcrumbs({breadcrumbs, backAction}: BreadcrumbsProps) {
20+
const breadcrumb =
21+
backAction ??
22+
(Array.isArray(breadcrumbs)
23+
? breadcrumbs[breadcrumbs.length - 1]
24+
: breadcrumbs);
2125
if (breadcrumb == null) {
26+
if (process.env.NODE_ENV === 'development') {
27+
// eslint-disable-next-line no-console
28+
console.warn(
29+
'Please provide a value to backAction, it will become required in the next major release.',
30+
);
31+
}
2232
return null;
2333
}
2434

polaris-react/src/components/Page/Page.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ export function Page({
4343
(rest.breadcrumbs != null &&
4444
Array.isArray(rest.breadcrumbs) &&
4545
rest.breadcrumbs.length > 0) ||
46-
rest.breadcrumbs != null;
46+
rest.breadcrumbs != null ||
47+
rest.backAction != null;
4748

4849
const contentClassName = classNames(
4950
!hasHeaderContent && styles.Content,

polaris-react/src/components/Page/components/Header/Header.tsx

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,10 @@ export interface HeaderProps extends TitleProps {
4949
primaryAction?: PrimaryAction | React.ReactNode;
5050
/** Page-level pagination */
5151
pagination?: PaginationProps;
52-
/** Collection of breadcrumbs */
52+
/** @deprecated Collection of breadcrumbs */
5353
breadcrumbs?: BreadcrumbsProps['breadcrumbs'];
54+
/** A back action link */
55+
backAction?: BreadcrumbsProps['backAction'];
5456
/** Collection of secondary page-level actions */
5557
secondaryActions?: MenuActionDescriptor[] | React.ReactNode;
5658
/** Collection of page-level groups of secondary actions */
@@ -77,6 +79,7 @@ export function Header({
7779
pagination,
7880
additionalNavigation,
7981
breadcrumbs,
82+
backAction,
8083
secondaryActions = [],
8184
actionGroups = [],
8285
compactTitle = false,
@@ -91,6 +94,12 @@ export function Header({
9194
'Deprecation: The `additionalNavigation` on Page is deprecated and will be removed in the next major version.',
9295
);
9396
}
97+
if (breadcrumbs && process.env.NODE_ENV === 'development') {
98+
// eslint-disable-next-line no-console
99+
console.warn(
100+
'Deprecation: The `breadcrumbs` prop on Page is deprecated and will be removed in the next major version. Please replace with a single `backAction`.',
101+
);
102+
}
94103

95104
const isSingleRow =
96105
!primaryAction &&
@@ -99,15 +108,27 @@ export function Header({
99108
isReactElement(secondaryActions)) &&
100109
!actionGroups.length;
101110

102-
const breadcrumbMarkup =
111+
let breadcrumbMarkup = null;
112+
if (backAction) {
113+
breadcrumbMarkup = (
114+
<div className={styles.BreadcrumbWrapper}>
115+
<Box maxWidth="100%" paddingInlineEnd="4" printHidden>
116+
<Breadcrumbs backAction={backAction} />
117+
</Box>
118+
</div>
119+
);
120+
} else if (
103121
(Array.isArray(breadcrumbs) && breadcrumbs.length > 0) ||
104-
(!Array.isArray(breadcrumbs) && breadcrumbs) ? (
122+
(!Array.isArray(breadcrumbs) && breadcrumbs)
123+
) {
124+
breadcrumbMarkup = (
105125
<div className={styles.BreadcrumbWrapper}>
106126
<Box maxWidth="100%" paddingInlineEnd="4" printHidden>
107127
<Breadcrumbs breadcrumbs={breadcrumbs} />
108128
</Box>
109129
</div>
110-
) : null;
130+
);
131+
}
111132

112133
const paginationMarkup =
113134
pagination && !isNavigationCollapsed ? (

polaris-react/src/components/Page/tests/Page.test.tsx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,29 @@ describe('<Page />', () => {
269269
});
270270
});
271271

272+
describe('backAction', () => {
273+
const backAction = {
274+
content: 'Products',
275+
onAction: noop,
276+
};
277+
278+
it('renders a <Header /> when defined', () => {
279+
const page = mountWithApp(
280+
<Page {...mockProps} backAction={backAction} />,
281+
);
282+
expect(page).toContainReactComponent(Header);
283+
});
284+
285+
it('gets passed into the <Header />', () => {
286+
const page = mountWithApp(
287+
<Page {...mockProps} backAction={backAction} />,
288+
);
289+
expect(page).toContainReactComponent(Header, {
290+
backAction,
291+
});
292+
});
293+
});
294+
272295
describe('divider', () => {
273296
it('renders border when divider is true and header props exist', () => {
274297
const wrapper = mountWithApp(<Page {...mockProps} divider />);

0 commit comments

Comments
 (0)