-
Notifications
You must be signed in to change notification settings - Fork 4.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
Allow define RadioControl label with ReactNode component #66615
base: trunk
Are you sure you want to change the base?
Conversation
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
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.
Sorry for the delay!
Like I noted in the original issue, I think a requirement for this change is that we stop using a <label>
internally and associate the input with a aria-labelledby
instead. The usage example in this PR already renders invalid HTML (<div>
inside a <label>
), so we can assume other consumers would make the same mistake 😄
*/ | ||
label: string; | ||
label: string | React.ReactNode; |
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.
ReactNode
is a bit broad. Do we really want label
to possibly be boolean
or null
or even number
? I wonder if we meant ReactElement
instead.
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.
Mmm, I don't think so. Maybe a number,
but I believe string
covers that.
Replacing...
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.
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.
Do we really want
label
to possibly beboolean
ornull
This is a reasonable point, but I think we should also consider how many of our components that accept non-string labels right now already accept ReactNode
. Introducing a subtle inconsistency like this could cause complications when composing components/types. Would it be ok to consider a package-wide switch from ReactNode
to ReactElement
as a separate issue?
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.
I'm happy to consider this a separate issue 👍 Let's document it in an issue though.
Never stop learning. Thanks a bunch for your :-) feedback |
Co-authored-by: Lena Morita <[email protected]>
Co-authored-by: Lena Morita <[email protected]>
Co-authored-by: Lena Morita <[email protected]>
Flaky tests detected in c6b9c9e. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/12055287484
|
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.
@@ -104,7 +104,8 @@ A function that receives the value of the new option that is being selected as i | |||
|
|||
An array of objects containing the value and label of the options. | |||
|
|||
- `label`: `string` The label to be shown to the user. | |||
- `label`: `ReactNode` The label to be shown to the user. When the label is not a string, make sure that the element is accessibly labeled. |
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.
Matching TypeScript types
- `label`: `ReactNode` The label to be shown to the user. When the label is not a string, make sure that the element is accessibly labeled. | |
- `label`: `string` | `React.ReactElement` The label to be shown to the user. When the label is not a string, make sure that the element is accessibly labeled. |
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.
Based on #66615 (comment), it looks like we may want to revert to ReactNode
. In that case, feel free to ignore my suggestion above, and instead let's change the TypeScript type back to ReactNode
.
Nothing from my end 👍 |
The internals need to be altered to stop using |
What?
This PR allows using a
ReactNode
element for label in the RadioControl componentWhy?
Because sometimes it's desired to render not only text for the radio control label
How?
ReactNode
for radio labelTesting Instructions
Testing Instructions for Keyboard
Screenshots or screencast