Skip to content

Commit

Permalink
ToolsPanel: Prevent calling deselect when panel remounts (#45673)
Browse files Browse the repository at this point in the history
* ToolsPanel: Prevent calling deselect when panel remounts

* Add link to comment

* Add changelog
  • Loading branch information
aaronrobertshaw authored Nov 10, 2022
1 parent d2ab8ff commit 0fc74ad
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
### Bug Fix

- `Autocomplete`: Fix unexpected block insertion during IME composition ([#45510](https://github.com/WordPress/gutenberg/pull/45510)).
- `ToolsPanelItem`: Prevent unintended calls to onDeselect when parent panel is remounted and item is rendered via SlotFill ([#45673](https://github.com/WordPress/gutenberg/pull/45673))

### Internal

Expand Down
6 changes: 5 additions & 1 deletion packages/components/src/tools-panel/tools-panel-item/hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,15 @@ export function useToolsPanelItem(
const menuGroup = isShownByDefault ? 'default' : 'optional';
const isMenuItemChecked = menuItems?.[ menuGroup ]?.[ label ];
const wasMenuItemChecked = usePrevious( isMenuItemChecked );
const isRegistered = menuItems?.[ menuGroup ]?.[ label ] !== undefined;

// Determine if the panel item's corresponding menu is being toggled and
// trigger appropriate callback if it is.
useEffect( () => {
if ( isResetting || ! hasMatchingPanel ) {
// We check whether this item is currently registered as items rendered
// via fills can persist through the parent panel being remounted.
// See: https://github.com/WordPress/gutenberg/pull/45673
if ( ! isRegistered || isResetting || ! hasMatchingPanel ) {
return;
}

Expand Down

0 comments on commit 0fc74ad

Please sign in to comment.