Skip to content

Commit

Permalink
Design Tools: Fix last ToolsPanelItem styling (#56536)
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronrobertshaw authored Nov 27, 2023
1 parent 4155c00 commit 0246a6b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
4 changes: 4 additions & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

- `Button`: Add focus rings to focusable disabled buttons ([#56383](https://github.com/WordPress/gutenberg/pull/56383)).

### Bug Fix

- `ToolsPanelItem`: Use useLayoutEffect to prevent rendering glitch for last panel item styling. ([#56536](https://github.com/WordPress/gutenberg/pull/56536)).

### Experimental

- `Tabs`: Memoize and expose the component context ([#56224](https://github.com/WordPress/gutenberg/pull/56224)).
Expand Down
13 changes: 11 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 @@ -2,7 +2,12 @@
* WordPress dependencies
*/
import { usePrevious } from '@wordpress/compose';
import { useCallback, useEffect, useMemo } from '@wordpress/element';
import {
useCallback,
useEffect,
useLayoutEffect,
useMemo,
} from '@wordpress/element';

/**
* Internal dependencies
Expand Down Expand Up @@ -59,7 +64,11 @@ export function useToolsPanelItem(

// Registering the panel item allows the panel to include it in its
// automatically generated menu and determine its initial checked status.
useEffect( () => {
//
// This is performed in a layout effect to ensure that the panel item
// is registered before it is rendered preventing a rendering glitch.
// See: https://github.com/WordPress/gutenberg/issues/56470
useLayoutEffect( () => {
if ( hasMatchingPanel && previousPanelId !== null ) {
registerPanelItem( {
hasValue: hasValueCallback,
Expand Down

0 comments on commit 0246a6b

Please sign in to comment.