Skip to content

Commit

Permalink
ToolsPanelItem: Add panelId check before calling toggle methods (#35375)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewserong authored Oct 6, 2021
1 parent 0ae0bde commit cdc5c15
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions packages/components/src/tools-panel/tools-panel-item/hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export function useToolsPanelItem(
// Determine if the panel item's corresponding menu is being toggled and
// trigger appropriate callback if it is.
useEffect( () => {
if ( isResetting ) {
if ( isResetting || currentPanelId !== panelId ) {
return;
}

Expand All @@ -99,7 +99,14 @@ export function useToolsPanelItem(
if ( ! isMenuItemChecked && wasMenuItemChecked ) {
onDeselect?.();
}
}, [ isMenuItemChecked, wasMenuItemChecked, isValueSet, isResetting ] );
}, [
currentPanelId,
isMenuItemChecked,
isResetting,
isValueSet,
panelId,
wasMenuItemChecked,
] );

// The item is shown if it is a default control regardless of whether it
// has a value. Optional items are shown when they are checked or have
Expand Down

0 comments on commit cdc5c15

Please sign in to comment.