Skip to content

Commit

Permalink
Skip flagging item customization for optional items without value
Browse files Browse the repository at this point in the history
Because they should not cause themselves to be hidden.
  • Loading branch information
stokesman committed Apr 17, 2024
1 parent 80f3545 commit d25ef9b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
18 changes: 13 additions & 5 deletions packages/components/src/tools-panel/tools-panel-item/hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,19 @@ export function useToolsPanelItem(
const isRegistered = menuItems?.[ menuGroup ]?.[ label ] !== undefined;

const isValueSet = hasValue();
// Notify the panel when an item's value has changed.
useEffect(
() => flagItemCustomization( isValueSet, label, menuGroup ),
[ isValueSet, menuGroup, label, flagItemCustomization ]
);
// Notify the panel when an item's value has changed except for optional
// items without value because the item should not cause itself to hide.
useEffect( () => {
if ( ! isShownByDefault && ! isValueSet ) return;

flagItemCustomization( isValueSet, label, menuGroup );
}, [
isValueSet,
menuGroup,
label,
flagItemCustomization,
isShownByDefault,
] );

// Determine if the panel item's corresponding menu is being toggled and
// trigger appropriate callback if it is.
Expand Down
7 changes: 3 additions & 4 deletions packages/components/src/tools-panel/tools-panel/hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,9 @@ export function useToolsPanel(
} );
}, [ panelItems, setMenuItems, menuItemOrder ] );

// 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,
// we need to update that when their value is customized.
// Updates the status of the panel’s menu items. For default items the
// value represents whether it differs from the default and for optional
// items whether the item is shown.
const flagItemCustomization = useCallback(
(
value: boolean,
Expand Down

0 comments on commit d25ef9b

Please sign in to comment.