From 7ff0fe47f1fa27fe5025e748f57dbed346483b49 Mon Sep 17 00:00:00 2001 From: Daniel Leroux Date: Fri, 13 Sep 2019 08:37:57 -0400 Subject: [PATCH 1/2] allowing for non primary page action --- UNRELEASED.md | 1 + src/components/Page/components/Header/Header.tsx | 8 +++++--- .../Page/components/Header/tests/Header.test.tsx | 16 +++++++++++++++- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/UNRELEASED.md b/UNRELEASED.md index a54ef68b532..0a8b23de32c 100644 --- a/UNRELEASED.md +++ b/UNRELEASED.md @@ -19,6 +19,7 @@ Use [the changelog guidelines](https://git.io/polaris-changelog-guidelines) to f - Fixed `Modal` setting an invalid `id` on `aria-labelledby` when no `title` is set ([#2115](https://github.com/Shopify/polaris-react/pull/2115)) - Fixed error warnings in `Card` and `RollupActions` tests ([#2125](https://github.com/Shopify/polaris-react/pull/2125)) - Added default accessibility label from `ResourceItem` ([#2097](https://github.com/Shopify/polaris-react/pull/2097)) +- Allow for non-primary action in the `Header` actions ([#2137](https://github.com/Shopify/polaris-react/pull/2137)) ### Documentation diff --git a/src/components/Page/components/Header/Header.tsx b/src/components/Page/components/Header/Header.tsx index 3c72a2147c9..bbe787488e8 100644 --- a/src/components/Page/components/Header/Header.tsx +++ b/src/components/Page/components/Header/Header.tsx @@ -114,11 +114,13 @@ export class Header extends React.PureComponent { /> ); + const primary = + primaryAction && + (primaryAction.primary === undefined ? true : primaryAction.primary); + const primaryActionMarkup = primaryAction ? (
- {buttonsFrom(primaryAction, { - primary: true, - })} + {buttonsFrom(primaryAction, {primary})}
) : null; diff --git a/src/components/Page/components/Header/tests/Header.test.tsx b/src/components/Page/components/Header/tests/Header.test.tsx index 87d8f8639b7..432095e518f 100644 --- a/src/components/Page/components/Header/tests/Header.test.tsx +++ b/src/components/Page/components/Header/tests/Header.test.tsx @@ -87,7 +87,7 @@ describe('
', () => { }); describe('primaryAction', () => { - it('renders a button based on the given action', () => { + it('renders a `primary` button based on the given action', () => { const primaryAction: HeaderPrimaryAction = { content: 'Click me!', }; @@ -99,6 +99,20 @@ describe('
', () => { const expectedButton = buttonsFrom(primaryAction, {primary: true}); expect(header.contains(expectedButton)).toBeTruthy(); }); + + it('renders a regular button based on the given action when primary is set to false', () => { + const primaryAction: HeaderPrimaryAction = { + content: 'Click me!', + primary: false, + }; + + const header = mountWithAppProvider( +
, + ); + + const expectedButton = buttonsFrom(primaryAction, {primary: false}); + expect(header.contains(expectedButton)).toBeTruthy(); + }); }); describe('pagination', () => { From ff48539cd81119ae456bd7c663b12a2766a05a03 Mon Sep 17 00:00:00 2001 From: Daniel Leroux Date: Fri, 13 Sep 2019 11:12:51 -0400 Subject: [PATCH 2/2] Update UNRELEASED.md Co-Authored-By: Chloe Rice --- UNRELEASED.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/UNRELEASED.md b/UNRELEASED.md index 0a8b23de32c..91ceea5e2ba 100644 --- a/UNRELEASED.md +++ b/UNRELEASED.md @@ -19,7 +19,7 @@ Use [the changelog guidelines](https://git.io/polaris-changelog-guidelines) to f - Fixed `Modal` setting an invalid `id` on `aria-labelledby` when no `title` is set ([#2115](https://github.com/Shopify/polaris-react/pull/2115)) - Fixed error warnings in `Card` and `RollupActions` tests ([#2125](https://github.com/Shopify/polaris-react/pull/2125)) - Added default accessibility label from `ResourceItem` ([#2097](https://github.com/Shopify/polaris-react/pull/2097)) -- Allow for non-primary action in the `Header` actions ([#2137](https://github.com/Shopify/polaris-react/pull/2137)) +- Reverted `Page.primaryAction` forcing `primary` to be `true` ([#2137](https://github.com/Shopify/polaris-react/pull/2137)) ### Documentation