Skip to content

Commit

Permalink
Consolidating comment and reinstating false as the default value fo…
Browse files Browse the repository at this point in the history
…r the state var `areAllOptionalControlsHidden`
  • Loading branch information
ramonjd committed Oct 13, 2021
1 parent cdc1702 commit 75e37a3
Showing 1 changed file with 19 additions and 21 deletions.
40 changes: 19 additions & 21 deletions packages/components/src/tools-panel/tools-panel/hook.ts
Expand Up @@ -92,27 +92,6 @@ export function useToolsPanel(
setMenuItems( items );
}, [ panelItems ] );

// Track whether optional controls, if any, are displayed or not.
// Default state is that all optional controls, if any, are hidden.
const [
areAllOptionalControlsHidden,
setAreAllOptionalControlsHidden,
] = useState( true );

// Where no optional menu items are active, we display a plus icon
// to indicate the presence of further menu items.
useEffect( () => {
if ( menuItems.optional ) {
const optionalMenuItemsArray = Object.entries( menuItems.optional );
const newValue =
optionalMenuItemsArray.length > 0 &&
! optionalMenuItemsArray.some(
( [ , isSelected ] ) => isSelected
);
setAreAllOptionalControlsHidden( newValue );
}
}, [ menuItems.optional ] );

// Force a menu item to be checked.
// This is intended for use with default panel items. They are displayed
// separately to optional items and have different display states,
Expand All @@ -130,6 +109,25 @@ export function useToolsPanel(
} );
};

// Whether all optional menu items are hidden or not must be tracked
// in order to later determine if the panel display is empty and handle
// conditional display of a plus icon to indicate the presence of further
// menu items.
const [
areAllOptionalControlsHidden,
setAreAllOptionalControlsHidden,
] = useState( false );

useEffect( () => {
if ( menuItems.optional ) {
const optionalItems = Object.entries( menuItems.optional );
const allControlsHidden =
optionalItems.length > 0 &&
! optionalItems.some( ( [ , isSelected ] ) => isSelected );
setAreAllOptionalControlsHidden( allControlsHidden );
}
}, [ menuItems.optional ] );

const cx = useCx();
const classes = useMemo( () => {
const hasDefaultMenuItems =
Expand Down

0 comments on commit 75e37a3

Please sign in to comment.