Skip to content

Commit

Permalink
Removing duplicate <a href /> wrapper
Browse files Browse the repository at this point in the history
Adding disabled onClick and aria attribute
  • Loading branch information
ramonjd committed Oct 19, 2023
1 parent c88b287 commit eb7b03a
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions packages/block-library/src/image/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ const scaleOptions = [
},
];

const disabledClickProps = {
onClick: ( event ) => event.preventDefault(),
'aria-disabled': true,
};

export default function Image( {
temporaryURL,
attributes,
Expand Down Expand Up @@ -769,9 +774,7 @@ export default function Image( {
} }
resizeRatio={ align === 'center' ? 2 : 1 }
>
{ /* If the image has a href, wrap in an <a /> tag to trigger any inherited link element styles */ }
{ /* eslint-disable-next-line jsx-a11y/anchor-is-valid */ }
{ !! href ? <a>{ img }</a> : img }
{ img }
</ResizableBox>
);
}
Expand All @@ -786,8 +789,13 @@ export default function Image( {
which causes duplicated image upload. */ }
{ ! temporaryURL && controls }
{ /* If the image has a href, wrap in an <a /> tag to trigger any inherited link element styles */ }
{ /* eslint-disable-next-line jsx-a11y/anchor-is-valid */ }
{ !! href ? <a>{ img }</a> : img }
{ !! href ? (
<a href={ href } { ...disabledClickProps }>
{ img }
</a>
) : (
img
) }
{ showCaption &&
( ! RichText.isEmpty( caption ) || isSelected ) && (
<RichText
Expand Down

0 comments on commit eb7b03a

Please sign in to comment.