diff --git a/components/panel/body.js b/components/panel/body.js index f4243a65f837c..64aef1fae0043 100644 --- a/components/panel/body.js +++ b/components/panel/body.js @@ -26,16 +26,22 @@ class PanelBody extends Component { toggle( event ) { event.preventDefault(); - this.setState( ( state ) => ( { - opened: ! state.opened, - } ) ); + if ( this.props.opened === undefined ) { + this.setState( ( state ) => ( { + opened: ! state.opened, + } ) ); + } + + if ( this.props.onToggle ) { + this.props.onToggle(); + } } render() { - const { title, children } = this.props; - const { opened } = this.state; - const icon = `arrow-${ opened ? 'down' : 'right' }`; - const className = classnames( 'components-panel__body', { 'is-opened': opened } ); + const { title, children, opened } = this.props; + const isOpened = opened === undefined ? this.state.opened : opened; + const icon = `arrow-${ isOpened ? 'down' : 'right' }`; + const className = classnames( 'components-panel__body', { 'is-opened': isOpened } ); return (