Skip to content
Merged
Show file tree
Hide file tree
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
15 changes: 7 additions & 8 deletions packages/blocks/src/blocks/CoreButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,13 @@ export function CoreButton(props: CoreButtonFragmentProps) {
aria-label={attributes?.text}
id={attributes?.anchor}
className={attributes?.cssClassName}>
<Link legacyBehavior href={attributes?.url}>
<a
target={linkTarget}
className={attributes?.linkClassName}
rel={attributes?.rel}
style={style}>
<span>{attributes?.text}</span>
</a>
<Link
href={attributes.url}
target={linkTarget}
className={attributes?.linkClassName}
rel={attributes?.rel}
style={style}>
<span>{attributes?.text}</span>
</Link>
</div>
);
Expand Down
18 changes: 18 additions & 0 deletions packages/blocks/tests/blocks/CoreButton.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,24 @@ describe('<CoreButton />', () => {
);
});

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', () => {
Expand Down
Loading