@@ -44,8 +44,10 @@ export interface ExpandableSectionProps extends Omit<React.HTMLProps<HTMLDivElem
4444 * use the onToggle property of the expandable section toggle sub-component.
4545 */
4646 onToggle ?: ( event : React . MouseEvent , isExpanded : boolean ) => void ;
47- /** React node that appears in the attached toggle in place of the toggleText property. */
48- toggleContent ?: React . ReactNode ;
47+ /** React node that appears in the attached toggle in place of the toggleText property.
48+ * Can also be a function that receives the expanded state and returns a React node.
49+ */
50+ toggleContent ?: React . ReactNode | ( ( isExpanded : boolean ) => React . ReactNode ) ;
4951 /** Text that appears in the attached toggle. */
5052 toggleText ?: string ;
5153 /** Text that appears in the attached toggle when collapsed (will override toggleText if
@@ -246,6 +248,9 @@ class ExpandableSection extends Component<ExpandableSectionProps, ExpandableSect
246248 propOrStateIsExpanded
247249 ) ;
248250
251+ const computedToggleContent =
252+ typeof toggleContent === 'function' ? toggleContent ( propOrStateIsExpanded ) : toggleContent ;
253+
249254 const expandableToggle = ! isDetached && (
250255 < div className = { `${ styles . expandableSection } __toggle` } >
251256 < Button
@@ -265,7 +270,7 @@ class ExpandableSection extends Component<ExpandableSectionProps, ExpandableSect
265270 aria-label = { toggleAriaLabel }
266271 aria-labelledby = { toggleAriaLabelledBy }
267272 >
268- { toggleContent || computedToggleText }
273+ { computedToggleContent || computedToggleText }
269274 </ Button >
270275 </ div >
271276 ) ;
0 commit comments