Skip to content

Commit

Permalink
Make default controls still show after reset all
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronrobertshaw committed Jun 7, 2021
1 parent 813fce6 commit dc3e462
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions packages/components/src/block-support-panel/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import BlockSupportPanelTitle from './title';
const BlockSupportPanel = ( props ) => {
const { children, className, label: menuLabel, resetAll, title } = props;
const [ menuItems, setMenuItems ] = useState( {} );
const [ defaultControls, setDefaultControls ] = useState( {} );

// If a block support UI has been disabled via theme.json a boolean `false`
// will be passed as a child. This panel is only interested in the children
Expand All @@ -29,13 +30,16 @@ const BlockSupportPanel = ( props ) => {
// of whether they have a value.
useEffect( () => {
const items = {};
const defaults = {};

filteredChildren.forEach( ( child ) => {
const { hasValue, isShownByDefault, label } = child.props;
items[ label ] = isShownByDefault || hasValue( child.props );
defaults[ label ] = isShownByDefault;
} );

setMenuItems( items );
setDefaultControls( defaults );
}, [] );

if ( filteredChildren.length === 0 ) {
Expand Down Expand Up @@ -70,11 +74,11 @@ const BlockSupportPanel = ( props ) => {
// Reset the block support attributes.
resetAll();

// Turn off all the controls in menu.
// Turn off menu items unless they are to display by default.
const resetMenuItems = {};

filteredChildren.forEach( ( child ) => {
resetMenuItems[ child.props.label ] = false;
filteredChildren.forEach( ( { props: { label } } ) => {
resetMenuItems[ label ] = defaultControls[ label ];
} );

setMenuItems( resetMenuItems );
Expand Down

0 comments on commit dc3e462

Please sign in to comment.