-
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
Block Supports: Switch dimensions inspector controls slot to bubble virtually #34725
Changes from 10 commits
220911c
326d3d2
8d238f7
72d556e
9b09362
8507363
e5809a8
5d4677c
0749b9b
84ba3b8
6d54a19
b1b93b5
a148041
540bcb3
ce2ef0a
022c19f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __experimentalToolsPanelContext as ToolsPanelContext } from '@wordpress/components'; | ||
import { useContext } from '@wordpress/element'; | ||
|
||
export default function BlockSupportSlotContainer( { Slot, ...props } ) { | ||
const toolsPanelContext = useContext( ToolsPanelContext ); | ||
return <Slot { ...props } fillProps={ toolsPanelContext } />; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ import warning from '@wordpress/warning'; | |
* Internal dependencies | ||
*/ | ||
import BlockSupportToolsPanel from './block-support-tools-panel'; | ||
import BlockSupportSlotContainer from './block-support-slot-container'; | ||
import groups from './groups'; | ||
|
||
export default function InspectorControlsSlot( { | ||
|
@@ -31,7 +32,11 @@ export default function InspectorControlsSlot( { | |
if ( label ) { | ||
return ( | ||
<BlockSupportToolsPanel group={ group } label={ label }> | ||
<Slot { ...props } bubblesVirtually={ bubblesVirtually } /> | ||
<BlockSupportSlotContainer | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. At this point in time that's correct. I didn't find a better option given the tools panel context isn't created until the With the current approach, there is also an issue with maintaining the order of rendered items in the panel when they are injected from multiple places. I'm definitely open to suggestions on improving this. Another option I was planning to explore but expect some issues with was, to see if I could set up ref forwarding for the As I mentioned, I'm probably missing something with that idea. Let me know if there are any fatal flaws with it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I haven't had much luck trying to find a working solution to avoid this or the fact the virtual bubbling slot introduces a div when it would be preferential to avoid that inside the One problem I ran into was that the virtual bubbling slots do not appear to accept a function as a child as per the normal slot component.
The docs do not appear to make any distinction here. @gziolo or @youknowriad can you confirm if this is an issue with the docs or whether the virtual bubbling slot component should also offer that? While exploring this, it looked like it might be possible to leverage the |
||
{ ...props } | ||
bubblesVirtually={ bubblesVirtually } | ||
Slot={ Slot } | ||
/> | ||
</BlockSupportToolsPanel> | ||
); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,12 +18,17 @@ const ToolsPanelItem = ( | |
props: WordPressComponentProps< ToolsPanelItemProps, 'div' >, | ||
forwardedRef: Ref< any > | ||
) => { | ||
const { children, isShown, ...toolsPanelItemProps } = useToolsPanelItem( | ||
props | ||
); | ||
const { | ||
children, | ||
isShown, | ||
shouldRenderPlaceholder, | ||
...toolsPanelItemProps | ||
} = useToolsPanelItem( props ); | ||
|
||
if ( ! isShown ) { | ||
return null; | ||
return shouldRenderPlaceholder ? ( | ||
aaronrobertshaw marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<View { ...toolsPanelItemProps } ref={ forwardedRef } /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if we should force a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it makes a difference for visual items like pictures or icons. |
||
) : null; | ||
} | ||
|
||
return ( | ||
|
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
header
prop is no longer used. I missed this when separating the ToolsPanel changes from those adding the ToolsPanel and Dimensions slot in #34157