diff --git a/packages/blocks/src/blocks/CoreButton.tsx b/packages/blocks/src/blocks/CoreButton.tsx index 6e36dc23f..f5fcc9ee1 100644 --- a/packages/blocks/src/blocks/CoreButton.tsx +++ b/packages/blocks/src/blocks/CoreButton.tsx @@ -34,14 +34,13 @@ export function CoreButton(props: CoreButtonFragmentProps) { aria-label={attributes?.text} id={attributes?.anchor} className={attributes?.cssClassName}> - - - {attributes?.text} - + + {attributes?.text} ); diff --git a/packages/blocks/tests/blocks/CoreButton.test.tsx b/packages/blocks/tests/blocks/CoreButton.test.tsx index 8edbb3565..d12db9c4b 100644 --- a/packages/blocks/tests/blocks/CoreButton.test.tsx +++ b/packages/blocks/tests/blocks/CoreButton.test.tsx @@ -28,6 +28,24 @@ describe('', () => { ); }); + test('puts the link attributes on a single anchor', () => { + const { container } = renderProvider({ + attributes: { + text: 'Click', + url: '/about', + linkClassName: 'wp-block-button__link', + linkTarget: '_blank', + rel: 'noopener', + }, + }); + const link = screen.getByRole('link', { name: 'Click' }); + expect(link).toHaveAttribute('href', '/about'); + expect(link).toHaveAttribute('target', '_blank'); + expect(link).toHaveAttribute('rel', 'noopener'); + expect(link).toHaveClass('wp-block-button__link'); + expect(container.querySelectorAll('a')).toHaveLength(1); + }); + // WordPress 7.0+ stores text alignment in style.typography.textAlign and // adds the has-text-align-* class to the saved markup. test('keeps text alignment from WordPress 7.0+ through the class name', () => {