Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ToolsPanelItem: Add panelId check before calling toggle methods #35375

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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