-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix missing Replace button in content-locked Image blocks (#53410)
* Revert "don't display BlockContextualToolbar at all in contentonly locking (#53110)" This reverts commit 5efce0e. * Alternative fix to hide BlockContextualToolbar when there are no controls
- Loading branch information
1 parent
21af8f7
commit ae17ef7
Showing
3 changed files
with
44 additions
and
10 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
packages/block-editor/src/components/block-controls/use-has-block-controls.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __experimentalUseSlotFills as useSlotFills } from '@wordpress/components'; | ||
import warning from '@wordpress/warning'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import groups from './groups'; | ||
|
||
export function useHasAnyBlockControls() { | ||
let hasAnyBlockControls = false; | ||
for ( const group in groups ) { | ||
// It is safe to violate the rules of hooks here as the `groups` object | ||
// is static and will not change length between renders. Do not return | ||
// early as that will cause the hook to be called a different number of | ||
// times between renders. | ||
// eslint-disable-next-line react-hooks/rules-of-hooks | ||
if ( useHasBlockControls( group ) ) { | ||
hasAnyBlockControls = true; | ||
} | ||
} | ||
return hasAnyBlockControls; | ||
} | ||
|
||
export function useHasBlockControls( group = 'default' ) { | ||
const Slot = groups[ group ]?.Slot; | ||
const fills = useSlotFills( Slot?.__unstableName ); | ||
if ( ! Slot ) { | ||
warning( `Unknown BlockControls group "${ group }" provided.` ); | ||
return null; | ||
} | ||
return !! fills?.length; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters