Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure disable overrides button is active for image blocks with captions or links #62948

Merged
merged 1 commit into from
Jun 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions packages/patterns/src/components/pattern-overrides-controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand Down Expand Up @@ -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 (
<>
Expand All @@ -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>
Expand Down
Loading