-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
CustomSelectControlV2: Add root element wrapper #62803
Conversation
e29ca7a
to
078a2de
Compare
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. |
...restProps | ||
} = props; | ||
|
||
return ( | ||
<> | ||
// Where should `restProps` be forwarded to? |
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.
This is something unrelated to this PR, but that we should definitely discuss.
Currently, ...restProps
are assumed to be intended for CustomSelectButton
, but I'd argue that folks would expect that most attributes would be assigned to the root wrapper (which will likely become BaseControl
)
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 think it should be the CustomSelectButton
. Is there anything other than className
that you'd want to pass to the root wrapper? I'm thinking about refs and event listeners, which would pass more naturally onto the button.
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 worried that if we start adding exceptions like className
, devEx will suffer because it won't be clear where each prop will be forwarded to. Also, if a consumer of the component wanted to set a className
on the trigger button, how would they do it?
Another though: if we don't pass any props to the root wrapper element, do you see that as a limitation for consumers? For example,:
- let's say that as a consumer I want to hide
CustomSelectControl
— settingdisplay: none
would only hide the button, but keep the label around - let's say I'm rendering
CustomSelectControlV2
inside a flexbox parent, and I'd like to setflex-shring
on it. UsingclassName
orstyle
won't cut it, since those styles should be applied to the root wrapper. The only way to achieve that will be to add an external wrapper component toCustomSelectControlV2
.
I think that this is a broader conversation that we need to have as we export components that internally compose smaller components.
For example, in DropdownMenuV2
we solved this by exporting a separate Trigger
subcomponent, and exposing a trigger
render prop. Which means that props by default can be passed to the root element, while trigger-specific props are passed directly to the Trigger
subcomponent.
Curious to hear @DaniGuardiola 's thoughts on this one too.
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.
Looks good 🚀
@@ -21,6 +22,7 @@ function CustomSelectControl( props: LegacyCustomSelectProps ) { | |||
onChange, | |||
size = 'default', | |||
value, | |||
className: classNameProp, |
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.
Why the rename?
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.
Because I would otherwise get a 'className' is already declared in the upper scope
linting error later in the file where options
is mapped into <CustomSelectItem />
s
...restProps | ||
} = props; | ||
|
||
return ( | ||
<> | ||
// Where should `restProps` be forwarded to? |
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 think it should be the CustomSelectButton
. Is there anything other than className
that you'd want to pass to the root wrapper? I'm thinking about refs and event listeners, which would pass more naturally onto the button.
078a2de
to
1374b58
Compare
I'm going to merge once CI cheks pass — although we should continue the conversation in #62803 (comment) and work on it via a follow-up as necessary. |
What?
Extracted from #62424
Add a root element wrapper to
CustomSelectControlV2
Why?
CustomSelectControl
(eg. if the parent hasdisplay: flex
, which is what happens when usingCustomSelectControl
as a direct child ofToolsPanelItem
)components-custom-select-control
classNameHow?
Adding a root element wrapper (ie a
div
) instead of a React Fragment, wrapping label + button under one element.Testing Instructions
In the editor
To test in the editor, apply this patch
Click to expand