From cdc5c152554773c340dbcc386066d1b96a5b0143 Mon Sep 17 00:00:00 2001 From: Andrew Serong <14988353+andrewserong@users.noreply.github.com> Date: Wed, 6 Oct 2021 16:30:12 +1100 Subject: [PATCH] ToolsPanelItem: Add panelId check before calling toggle methods (#35375) --- .../src/tools-panel/tools-panel-item/hook.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/components/src/tools-panel/tools-panel-item/hook.ts b/packages/components/src/tools-panel/tools-panel-item/hook.ts index 57189eea3916a7..3b3762cd827821 100644 --- a/packages/components/src/tools-panel/tools-panel-item/hook.ts +++ b/packages/components/src/tools-panel/tools-panel-item/hook.ts @@ -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; } @@ -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