Skip to content

Commit

Permalink
SlotFill: Allow contextual SlotFillProviders (#56779)
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad authored and artemiomorales committed Jan 4, 2024
1 parent ddd4d74 commit cfc226f
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/block-editor/src/components/provider/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const ExperimentalBlockEditorProvider = withRegistryProvider(
useBlockSync( props );

return (
<SlotFillProvider>
<SlotFillProvider passthrough>
<KeyboardShortcuts.Register />
<BlockRefsProvider>{ children }</BlockRefsProvider>
</SlotFillProvider>
Expand Down
1 change: 1 addition & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
- `ToggleGroupControl`: react correctly to external controlled updates ([#56678](https://github.com/WordPress/gutenberg/pull/56678)).
- `ToolsPanel`: fix a performance issue ([#56770](https://github.com/WordPress/gutenberg/pull/56770)).
- `BorderControl`: adjust `BorderControlDropdown` Button size to fix misaligned border ([#56730](https://github.com/WordPress/gutenberg/pull/56730)).
- `SlotFillProvider`: Restore contextual Slot/Fills within SlotFillProvider ([#56779](https://github.com/WordPress/gutenberg/pull/56779)).

### Internal

Expand Down
7 changes: 5 additions & 2 deletions packages/components/src/slot-fill/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,12 @@ export function UnforwardedSlot(
}
export const Slot = forwardRef( UnforwardedSlot );

export function Provider( { children }: SlotFillProviderProps ) {
export function Provider( {
children,
passthrough = false,
}: SlotFillProviderProps ) {
const parent = useContext( SlotFillContext );
if ( ! parent.isDefault ) {
if ( ! parent.isDefault && passthrough ) {
return <>{ children }</>;
}
return (
Expand Down
5 changes: 5 additions & 0 deletions packages/components/src/slot-fill/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ export type SlotFillProviderProps = {
* The children elements.
*/
children: ReactNode;

/**
* Whether to pass slots to the parent provider if existent.
*/
passthrough?: boolean;
};

export type SlotFillBubblesVirtuallySlotRef = RefObject< HTMLElement >;
Expand Down

0 comments on commit cfc226f

Please sign in to comment.