-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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 secondaryActions prop value for customizability #5495
Conversation
size-limit report 📦
|
df9ca8d
to
4be8a25
Compare
import {isValidElement} from 'react'; | ||
|
||
export function isInterface<T>(x: T | React.ReactNode): x is T { | ||
return !isValidElement(x) && x !== undefined; | ||
} | ||
|
||
export function isReactElement<T>(x: T): x is T { | ||
return isValidElement(x) && x !== undefined; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[question] These are the same util functions that are present for the Page
component. Is there an appropriate place we could refactor both copies into? Maybe utilities/components.tsx
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The utilities/components.tsx
file looks like a good place to me for such utilities if used globally for reusability, could polaris team confirm if our assumption is correct? 🙏
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes that's a good idea, you can make individual files named similarly to is-object.ts
👍🏽
4be8a25
to
a7aa2d7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for doing this, changes look good to me! 🚀
Let's wait for polaris team members to ✅ 🙏
import {isValidElement} from 'react'; | ||
|
||
export function isInterface<T>(x: T | React.ReactNode): x is T { | ||
return !isValidElement(x) && x !== undefined; | ||
} | ||
|
||
export function isReactElement<T>(x: T): x is T { | ||
return isValidElement(x) && x !== undefined; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The utilities/components.tsx
file looks like a good place to me for such utilities if used globally for reusability, could polaris team confirm if our assumption is correct? 🙏
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
<Button | ||
connectedDisclosure={{ | ||
accessibilityLabel: 'Other save actions', | ||
actions: [{content: 'Save as new'}], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actions: [{content: 'Save as new'}], | |
actions: [{content: 'Save as draft'}], |
polaris-react/UNRELEASED.md
Outdated
@@ -8,6 +8,8 @@ Use [the changelog guidelines](/documentation/Versioning%20and%20changelog.md) t | |||
|
|||
- Added `icon` prop to the `Badge` component ([#5292](https://github.com/Shopify/polaris/pull/5292)) | |||
|
|||
- Added `ReactNode` as an accepted prop type to `secondaryActions` on the `PageActions` component ([#5495](https://github.com/Shopify/polaris/pull/5495)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Added `ReactNode` as an accepted prop type to `secondaryActions` on the `PageActions` component ([#5495](https://github.com/Shopify/polaris/pull/5495)) | |
- Added support for setting a `ReactNode` on the `PageActions` `secondaryActions` prop ([#5495](https://github.com/Shopify/polaris/pull/5495)) |
import {isValidElement} from 'react'; | ||
|
||
export function isInterface<T>(x: T | React.ReactNode): x is T { | ||
return !isValidElement(x) && x !== undefined; | ||
} | ||
|
||
export function isReactElement<T>(x: T): x is T { | ||
return isValidElement(x) && x !== undefined; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes that's a good idea, you can make individual files named similarly to is-object.ts
👍🏽
actions: [{content: 'Save as new'}], | ||
}} | ||
> | ||
Save as new |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Save as new | |
Save |
a7aa2d7
to
3a6f374
Compare
3a6f374
to
d5888b6
Compare
🎉 Thanks for your contribution to Polaris React! |
WHY are these changes introduced?
This PR is related to a similar recent change to
secondaryActions
onPage
.Currently
secondaryActions
onPageActions
only allows for passing props asComplexAction[]
which doesn't allow for flexibility and results in accessibility issues in some cases.In cases where secondary actions open 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 secondary action to leverage modal's built-in focus management, or through passing a custom button that'd able to have aref
to receive the focus.WHAT is this pull request doing?
This PR maintains the existing
secondaryActions
prop, while adding the option to pass aReactNode
instead for customizability.How to 🎩
🖥 Local development instructions
🗒 General tophatting guidelines
📄 Changelog guidelines
Copy-paste this code in
playground/Playground.tsx
:🎩 checklist
README.md
with documentation changes