Skip to content

Commit

Permalink
SlotFill: Allow contextual SlotFillProviders
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad committed Dec 5, 2023
1 parent 308fc42 commit 7627ff3
Show file tree
Hide file tree
Showing 3 changed files with 11 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
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 7627ff3

Please sign in to comment.