@@ -50,7 +50,9 @@ export interface TriggerRef {
5050// New version will not wrap popup with `rc-trigger-popup-content` when multiple children
5151
5252export interface TriggerProps {
53- children : React . ReactElement < any > ;
53+ children :
54+ | React . ReactElement < any >
55+ | ( ( info : { open : boolean } ) => React . ReactElement < any > ) ;
5456 action ?: ActionType | ActionType [ ] ;
5557 showAction ?: ActionType [ ] ;
5658 hideAction ?: ActionType [ ] ;
@@ -261,9 +263,6 @@ export function generateTrigger(
261263 }
262264 } ) ;
263265
264- // ========================== Children ==========================
265- const child = React . Children . only ( children ) ;
266- const originChildProps = child ?. props || { } ;
267266 const cloneProps : Pick <
268267 React . HTMLAttributes < HTMLElement > ,
269268 | 'onClick'
@@ -311,6 +310,17 @@ export function generateTrigger(
311310 // Render still use props as first priority
312311 const mergedOpen = popupVisible ?? internalOpen ;
313312
313+ // ========================== Children ==========================
314+ const child = React . useMemo ( ( ) => {
315+ const nextChild =
316+ typeof children === 'function'
317+ ? children ( { open : mergedOpen } )
318+ : children ;
319+ return React . Children . only ( nextChild ) ;
320+ } , [ children , mergedOpen ] ) ;
321+
322+ const originChildProps = child ?. props || { } ;
323+
314324 // We use effect sync here in case `popupVisible` back to `undefined`
315325 const setMergedOpen = useEvent ( ( nextOpen : boolean ) => {
316326 if ( openUncontrolled ) {
0 commit comments