Skip to content
Open
Next Next commit
Add filter prop to slot fills
  • Loading branch information
jeryj committed Sep 5, 2025
commit 9d99bdd01d57ff0056c5c7d11959b121a048a740
7 changes: 5 additions & 2 deletions packages/components/src/slot-fill/slot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ function Slot( props: Omit< SlotComponentProps, 'bubblesVirtually' > ) {
const registry = useContext( SlotFillContext );
const instanceRef = useRef( {} );

const { name, children, fillProps = {} } = props;
const { name, children, fillProps = {}, filter } = props;

useLayoutEffect( () => {
const instance = instanceRef.current;
Expand All @@ -68,7 +68,10 @@ function Slot( props: Omit< SlotComponentProps, 'bubblesVirtually' > ) {
fills = [];
}

const renderedFills = fills
// Apply filter function if provided
const filteredFills = filter ? fills.filter( filter ) : fills;

const renderedFills = filteredFills
.map( ( fill ) => {
const fillChildren = isFunction( fill.children )
? fill.children( fillProps )
Expand Down
17 changes: 17 additions & 0 deletions packages/components/src/slot-fill/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ type SlotPropBase = {
fillProps?: FillProps;
};

export type FillFilter = ( fill: {
instance: FillInstance;
children: FillChildren;
} ) => boolean;

export type SlotComponentProps =
| ( SlotPropBase & {
/**
Expand All @@ -56,6 +61,12 @@ export type SlotComponentProps =
* Supported only when `bubblesVirtually` is `true`.
*/
style?: React.CSSProperties;

/**
* Optional filter function to control which fills are rendered.
* Returns true to include the fill, false to exclude it.
*/
filter?: FillFilter;
} )
| ( SlotPropBase & {
/**
Expand All @@ -82,6 +93,12 @@ export type SlotComponentProps =
* Supported only when `bubblesVirtually` is `true`.
*/
style?: never;

/**
* Optional filter function to control which fills are rendered.
* Returns true to include the fill, false to exclude it.
*/
filter?: FillFilter;
} );

export type FillChildren =
Expand Down