-
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
Add second parameter to createSlotFill to define wrapper element for Slot #6920
Add second parameter to createSlotFill to define wrapper element for Slot #6920
Conversation
cc @gziolo |
Did you try just replacing the wrapper |
return ( | ||
<div ref={ this.bindNode }> | ||
<SlotWrap ref={ this.bindNode }> |
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.
@aduth - can we use Fragment
here and omit ref
part?
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.
@gziolo would using Fragment
be preferable to passing the component? If so, I can do another PR to that end.
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, I don't think we want this to be a meaningful node. Currently it's used as the target for rendering portal children.
gutenberg/components/slot-fill/fill.js
Line 73 in 5ebefc3
return createPortal( children, slot.node ); |
So, we probably need the ref
still (since createPortal
requires a DOM node target). While I agree #6839 is a problem, I don't think we want developers to be concerned with controlling this wrapper (since, again, it needn't exist as a meaningful node).
Two things we could explore:
- The
bubbleVirtually = false
variation of aFill
may not require the wrapper, since it's not usingcreatePortal
- Though, I'd like to encourage the virtual variation, maybe eventually deprecate
bubbleVirtually = false
unless this wrapper business becomes too much an issue
- Though, I'd like to encourage the virtual variation, maybe eventually deprecate
- Assign the portal target node as the parent from which the slot is rendered, and avoid the wrapper node.
- Maybe assign
ref
to a temporary node, register slot with temporary node's parent, then remove temporary node?
- Maybe assign
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.
Should we open an issue based on @aduth's comment and close this one? I don't think the changes proposed in this PR align with how we want to move forward. We definitely want to improve the general experience with Slot & Fill pair and eventually remove the need to wrap Slots with <div />
.
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.
See #7231
Description
This PR adds an optional second parameter to createSlotFill that allows control over the element that wraps the
children
. This fixes #6839 and relates to #6867 and feels like a better approach than one I proposed in #6905How has this been tested?
I have tested via
npm run test
and using the following:I am seeing a React warning that is due to adding a ref to a stateless component which is due to using PanelRow as the wrapper component. I think we can address if this approach is deemed suitable.
Checklist: