-
Notifications
You must be signed in to change notification settings - Fork 1.2k
[AnnotatedSection] Update type definition for title prop to accept React.ReactNode #1431
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
Conversation
👋 Thanks for opening your first pull request. A contributor should give feedback soon. If you haven’t already, please check out the contributing guidelines. You can also join #polaris on the Shopify Partners Slack. |
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.
Looking at how AnnotatedSection
handles a title
, and it passes the prop down to its own Heading
component. That component then wraps the title
string in an h2
. That wouldn't necessarily make for valid markup depending on what is passed here.
We should be conditionally wrapping it in the Heading
based on the prop's type like we do in other components which have had this requirement relaxed. You'll also want to add tests for that condition
Thanks for pointing that out, @danrosenthal! Should I something to the README that recommends including a or in the component being passed to the
|
0ab7b02
to
683c21a
Compare
@francinen looks like this needs some formatting on the UNRELEASED doc |
Thanks for opening this up @francinen and sorry about being told one thing in slack and another in GitHub by different people.
I disagree with this behaviour. I think changing the wrapping component based up on if we pass a string or a ReactNode is very unintuitive and we should not do it. I don't think consumers will realize that changing We want to discourage lots of content within the section header and I think making it so that your title is always wrapped in a It also looks like wrapping is currently the exception rather than the rule in the vast majority of cases: Taking a look at existing components accept a prop that can be a ReactNode (and could be either a thus either a string or an element):
In addition every instance of the Not wrapping is clearly a more prevalent option. It's only Card/Card.Section titles, Layout.AnnotatedSection descriptions and Navigation.Item badges that pull this trick. |
Also ping @ry5n and @yourpalsonja also as you both had opinions on this when I asked in Slack:
|
That's good feedback @BPScott! Thanks for pointing out that this is the exception rather than the rule. This feels like one of those best practices we should be documenting once we've reached consensus on it. |
@danrosenthal with all that in mind, do you have an updated opinion of what this PR should do? Do you think we should keep the "only wrap in a Heading if it's a string" logic that @francinen added in 683c21a or should we revert that commit? (For the record I'm firmly in the "avoid changing behaviour based on types, lets the revert that commit" camp) |
+1, this sounds like the right approach Ben. @francinen please let me know if you have any questions |
683c21a
to
e07dc98
Compare
Thanks for all the context, @BPScott and @danrosenthal! I reverted that last commit and fixed the formatting issues in the UNRELEASED.md. |
e07dc98
to
86a66d9
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.
86a66d9
to
9488dfa
Compare
…ccept React.ReactNode
9488dfa
to
b90ce21
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.
🚢 on 🍏
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!
🎉 Thanks for your contribution to Polaris React! |
WHY are these changes introduced?
We came across a use case where we wanted to render another component, such as a
Badge
alongside the heading for anAnnotatedSection
:We considered passing a React component to the
title
prop that rendered both aHeading
and aBadge
component:While this renders successfuly in the browser, it raises a TypeScript error in the text editor because, at the moment, the
title
prop only supports strings.After consulting @BPScott, we felt it seemed reasonable to change the type restriction for the
title
prop in this scenario: https://shopify.slack.com/archives/C8H54T86Q/p1557331031274400WHAT is this pull request doing?
This PR updates the type definition for the
title
prop of theAnnotatedSection
component to acceptReact.ReactNode
instead ofstring
.How to 🎩
🖥 Local development instructions
🗒 General tophatting guidelines
📄 Changelog guidelines
Copy-paste this code in
playground/Playground.tsx
:🎩 checklist
README.md
with documentation changes