From b9db3e1c82b195909f4c0108a4cbb14ffc82646d Mon Sep 17 00:00:00 2001 From: Daniel Richards Date: Fri, 28 Jun 2024 14:35:03 +0800 Subject: [PATCH] Ensure "disable overrides" button is active for image blocks with captions or links (#62948) Co-authored-by: talldan Co-authored-by: kevin940726 --- .../components/pattern-overrides-controls.js | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/packages/patterns/src/components/pattern-overrides-controls.js b/packages/patterns/src/components/pattern-overrides-controls.js index e2c74e76965839..b8af8538d8b358 100644 --- a/packages/patterns/src/components/pattern-overrides-controls.js +++ b/packages/patterns/src/components/pattern-overrides-controls.js @@ -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' ) }