@@ -130,26 +130,29 @@ class ToolbarFilter extends Component<ToolbarFilterProps, ToolbarFilterState> {
130130 ) : null ;
131131
132132 if ( ! _isExpanded && this . state . isMounted ) {
133+ const collapsedLabelPortalTarget = labelGroupContentRef ?. current ?. firstElementChild ?? null ;
133134 return (
134135 < Fragment >
135136 { showToolbarItem && < ToolbarItem { ...props } > { children } </ ToolbarItem > }
136- { labelGroupContentRef ?. current ?. firstElementChild !== null &&
137- ReactDOM . createPortal ( labelGroup , labelGroupContentRef . current . firstElementChild ) }
137+ { collapsedLabelPortalTarget !== null && ReactDOM . createPortal ( labelGroup , collapsedLabelPortalTarget ) }
138138 </ Fragment >
139139 ) ;
140140 }
141141
142142 return (
143143 < ToolbarContentContext . Consumer >
144- { ( { labelContainerRef } ) => (
145- < Fragment >
146- { showToolbarItem && < ToolbarItem { ...props } > { children } </ ToolbarItem > }
147- { labelContainerRef . current && ReactDOM . createPortal ( labelGroup , labelContainerRef . current ) }
148- { expandableLabelContainerRef &&
149- expandableLabelContainerRef . current &&
150- ReactDOM . createPortal ( labelGroup , expandableLabelContainerRef . current ) }
151- </ Fragment >
152- ) }
144+ { ( { labelContainerRef } ) => {
145+ const labelContainer = labelContainerRef ?. current ?? null ;
146+ return (
147+ < Fragment >
148+ { showToolbarItem && < ToolbarItem { ...props } > { children } </ ToolbarItem > }
149+ { labelContainer !== null && ReactDOM . createPortal ( labelGroup , labelContainer ) }
150+ { expandableLabelContainerRef &&
151+ expandableLabelContainerRef . current &&
152+ ReactDOM . createPortal ( labelGroup , expandableLabelContainerRef . current ) }
153+ </ Fragment >
154+ ) ;
155+ } }
153156 </ ToolbarContentContext . Consumer >
154157 ) ;
155158 }
0 commit comments