Skip to content

Components: ExternalLink onClick event handler is not working #45212

@Initsogar

Description

@Initsogar

Description

We are using ExternalLink on multiple instances in Jetpack monorepo, using the onClick event handler to track clicks. After a recent change implemented, any code passed to onClick prop is being ignored by this component.

This is related to a recent change implemented for validating anchor links in #42259.

Step-by-step reproduction instructions

You can reproduce the bug by adding an onClick event handler to ExternalLink. After clicking the link, you will notice it is not calling doSomething function.

import { ExternalLink } from '@wordpress/components';
import { useCallback } from '@wordpress/element';

const MyExternalLink = () => {
	const doSomething = useCallback( () => {
		console.log( 'ExternalLink clicked!' );
	}, [] );

	return (
		<ExternalLink href="https://wordpress.org" onClick={ doSomething }>
			WordPress.org
		</ExternalLink>
	);
);

Screenshots, screen recording, code snippet

No response

Environment info

No response

Please confirm that you have searched existing issues in the repo.

Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

Yes

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions