Skip to content

Commit

Permalink
Ensure "disable overrides" button is active for image blocks with cap…
Browse files Browse the repository at this point in the history
…tions or links (#62948)

Co-authored-by: talldan <talldanwp@git.wordpress.org>
Co-authored-by: kevin940726 <kevin940726@git.wordpress.org>
  • Loading branch information
3 people authored Jun 28, 2024
1 parent 535c74f commit 6d3cc7a
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions packages/patterns/src/components/pattern-overrides-controls.js
Original file line number Diff line number Diff line change
@@ -44,7 +44,7 @@ function PatternOverridesControls( {

const hasName = !! attributes.metadata?.name;
const defaultBindings = attributes.metadata?.bindings?.__default;
const allowOverrides =
const hasOverrides =
hasName && defaultBindings?.source === PATTERN_OVERRIDES_BINDING_SOURCE;
const isConnectedToOtherSources =
defaultBindings?.source &&
@@ -79,13 +79,14 @@ function PatternOverridesControls( {
blockName === 'core/image' &&
( !! attributes.caption?.length || !! attributes.href?.length );

const helpText = hasUnsupportedImageAttributes
? __(
`Overrides currently don't support image captions or links. Remove the caption or link first before enabling overrides.`
)
: __(
'Allow changes to this block throughout instances of this pattern.'
);
const helpText =
! hasOverrides && hasUnsupportedImageAttributes
? __(
`Overrides currently don't support image captions or links. Remove the caption or link first before enabling overrides.`
)
: __(
'Allow changes to this block throughout instances of this pattern.'
);

return (
<>
@@ -101,16 +102,18 @@ function PatternOverridesControls( {
variant="secondary"
aria-haspopup="dialog"
onClick={ () => {
if ( allowOverrides ) {
if ( hasOverrides ) {
setShowDisallowOverridesModal( true );
} else {
setShowAllowOverridesModal( true );
}
} }
disabled={ hasUnsupportedImageAttributes }
disabled={
! hasOverrides && hasUnsupportedImageAttributes
}
__experimentalIsFocusable
>
{ allowOverrides
{ hasOverrides
? __( 'Disable overrides' )
: __( 'Enable overrides' ) }
</Button>

0 comments on commit 6d3cc7a

Please sign in to comment.