Router: Fix broken link interception and router navigation (#65023)

* Router: Fix broken link interception and router navigation

* replace with instanceof Element
This commit is contained in:
Torkel Ödegaard 2023-03-20 10:54:10 +01:00 committed by GitHub
parent 4a80233bed
commit 769b4598d7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3,7 +3,7 @@ import { locationService, navigationLogger } from '@grafana/runtime';
import { config } from 'app/core/config';
export function interceptLinkClicks(e: MouseEvent) {
const anchor = e.target instanceof HTMLElement ? getParentAnchor(e.target) : null;
const anchor = e.target instanceof Element && getParentAnchor(e.target);
// Ignore if opening new tab or already default prevented
if (e.ctrlKey || e.metaKey || e.defaultPrevented) {
@ -43,7 +43,7 @@ export function interceptLinkClicks(e: MouseEvent) {
}
}
function getParentAnchor(element: HTMLElement | null): HTMLElement | null {
function getParentAnchor(element: Element | null): Element | null {
while (element !== null && element.tagName) {
if (element.tagName.toUpperCase() === 'A') {
return element;