I have 2 toggle components that show/hide panels under them which is working fine. However, If I toggle the second panel I need to make sure the first panel is off. Same with the first, I don't want the two panels toggled open at once.
Here is a basic example of what I have.
<ToggleControl
label={__( 'Toggle One' )}
checked={ toggleOne }
onChange={ () => this.props.setAttributes({ toggleOne: ! toggleOne }) }
/>
{ toggleOne ?
<PanelBody>
... Show Panel 1 Stuff
</PanelBody>
: null }
<ToggleControl
label={__('Add Image Divider')}
checked={toggleTwo}
onChange={() => this.props.setAttributes({ toggleTwo: !toggleTwo })}
/>
{ toggleTwo ?
<PanelBody>
... Show Panel 2 Stuff
</PanelBody>
: null }
I can toggle the other panel inside the onChange() of the other toggle by doing this...
onChange={() => this.props.setAttributes({ toggleTwo: !toggleTwo, toggleOne: !toggleOne })}
But I don't want to toggle it if its already off and can't seem to figure it out.
Thanks.