Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PageActions] Add ReactNode as an accepted primaryAction prop value for customizability #5946

Merged
merged 6 commits into from
May 26, 2022

Conversation

rmleg
Copy link
Contributor

@rmleg rmleg commented May 25, 2022

WHY are these changes introduced?

This PR is related to recent changes to support passing a React.ReactNode to the secondaryActions prop of the PageActions component (and much of this PR's description is plagiarized from that one; thank you @stefanlegg!).

Currently primaryAction on PageActions only allows for passing props as DisableableAction & LoadableAction. This doesn't allow for flexibility and results in accessibility issues in some cases.

In cases where the primary action opens a modal, we are unable to move focus back to the button that opened it after the modal is closed. With this change to accept React.ReactNode we are better able to support keyboard users through passing an entire modal as the primary action to leverage modal's built-in focus management, or through passing a custom button with a ref to receive the focus.

This is also consistent with current behavior of the Page component, which can accept a React.ReactNode as its primaryAction prop.

WHAT is this pull request doing?

This PR maintains the existing primaryAction prop, while adding the option to pass a React.ReactNode instead for customizability.

I've also added a new example to the README for this component, highlighting this new supported prop type by passing in a custom button to primaryAction.

My new example in storybook

It displays a destructive delete button as the secondary action to the left, and a custom Save button with a drop-down arrow beside it as the primary action.

It also displays correctly on small mobile mode in storybook

My new example on the style guide site

The new example I added displays on the polaris-styleguide site running locally

Tophatted in web

The disabled button to the right has been passed in as a React.ReactNode.

The bottom of a page in settings showing a destructive delete pixel button on the left and a disabled connect pixel button on the right

How to 🎩

Use the Polaris snapshot release with polaris-styleguide (yarn add @shopify/polaris@0.0.0-snapshot-release-20220525220051) to verify that the new example displays in the documentation.

In storybook, verify that the PageActions/Page actions with custom primary action story displays a custom primary action, in this case a "Save" button with a drop-down option to "save as draft".

🎩 checklist

@rmleg
Copy link
Contributor Author

rmleg commented May 25, 2022

/snapshot-release

@github-actions
Copy link
Contributor

github-actions bot commented May 25, 2022

size-limit report 📦

Path Size
cjs 151.16 KB (+0.02% 🔺)
esm 87.51 KB (+0.03% 🔺)
esnext 138.39 KB (+0.02% 🔺)
css 37.78 KB (0%)

@alex-page
Copy link
Member

/snapit

@github-actions
Copy link
Contributor

🤌 ✨ Thanks @alex-page! Your snapshots have been shipped.

Test the snapshots by updating your package.json with the newly published versions:

yarn add @shopify/polaris-icons@0.0.0-snapshot-release-20220525204914
yarn add @shopify/polaris@0.0.0-snapshot-release-20220525204914
yarn add @shopify/polaris-tokens@0.0.0-snapshot-release-20220525204914
yarn add @shopify/stylelint-polaris@0.0.0-snapshot-release-20220525204914

@rmleg rmleg force-pushed the rmleg/page-actions-primary-action-react-node branch from b0c675f to b06e3c5 Compare May 25, 2022 21:14
@rmleg
Copy link
Contributor Author

rmleg commented May 25, 2022

/snapit

1 similar comment
@alex-page
Copy link
Member

/snapit

@alex-page
Copy link
Member

@rmleg there is still an issue with the permissions. Sorry about that. We will get that ironed out.

@github-actions
Copy link
Contributor

🤌 ✨ Thanks @alex-page! Your snapshots have been shipped.

Test the snapshots by updating your package.json with the newly published versions:

yarn add @shopify/polaris-icons@0.0.0-snapshot-release-20220525211817
yarn add @shopify/polaris@0.0.0-snapshot-release-20220525211817
yarn add @shopify/polaris-tokens@0.0.0-snapshot-release-20220525211817
yarn add @shopify/stylelint-polaris@0.0.0-snapshot-release-20220525211817

@rmleg
Copy link
Contributor Author

rmleg commented May 25, 2022

/snapit

@github-actions
Copy link
Contributor

🫰✨ Thanks @rmleg! Your snapshots have been published to npm.

Test the snapshots by updating your package.json with the newly published versions:

yarn add @shopify/polaris-icons@0.0.0-snapshot-release-20220525220051
yarn add @shopify/polaris@0.0.0-snapshot-release-20220525220051
yarn add @shopify/polaris-tokens@0.0.0-snapshot-release-20220525220051
yarn add @shopify/stylelint-polaris@0.0.0-snapshot-release-20220525220051

@rmleg
Copy link
Contributor Author

rmleg commented May 26, 2022

/snapit

@github-actions
Copy link
Contributor

🫰✨ Thanks @rmleg! Your snapshots have been published to npm.

Test the snapshots by updating your package.json with the newly published versions:

yarn add @shopify/polaris-icons@0.0.0-snapshot-release-20220526145039
yarn add @shopify/polaris@0.0.0-snapshot-release-20220526145039
yarn add @shopify/polaris-tokens@0.0.0-snapshot-release-20220526145039
yarn add @shopify/stylelint-polaris@0.0.0-snapshot-release-20220526145039

@rmleg rmleg changed the title WIP Rmleg/page actions primary action react node [PageActions] Add ReactNode as an accepted primaryAction prop value for customizability May 26, 2022
@rmleg rmleg marked this pull request as ready for review May 26, 2022 15:20
.changeset/four-doors-cheer.md Outdated Show resolved Hide resolved
@rmleg rmleg force-pushed the rmleg/page-actions-primary-action-react-node branch from 93650f9 to 62c3fb6 Compare May 26, 2022 20:57
@rmleg rmleg merged commit 3a5be82 into main May 26, 2022
@rmleg rmleg deleted the rmleg/page-actions-primary-action-react-node branch May 26, 2022 21:18
@github-actions github-actions bot mentioned this pull request May 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants