Skip to content

Commit ba61dc0

Browse files
committed
Fix typings + remove fake href
1 parent 6fced30 commit ba61dc0

2 files changed

Lines changed: 17 additions & 6 deletions

File tree

x-pack/plugins/endpoint/public/applications/endpoint/components/link_to_app.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

7-
import React, { memo } from 'react';
7+
import React, { memo, MouseEventHandler } from 'react';
88
import { EuiLink } from '@elastic/eui';
99
import { EuiLinkProps } from '@elastic/eui';
1010
import { useNavigateToAppEventHandler } from '../hooks/use_navigate_to_app_event_handler';
@@ -20,13 +20,13 @@ export const LinkToApp = memo<
2020
/** Any app specic path (route) */
2121
appPath?: string;
2222
appState?: any;
23+
onClick?: MouseEventHandler<HTMLButtonElement | HTMLAnchorElement>;
2324
}
2425
>(({ appId, appPath: path, appState: state, onClick, children, ...otherProps }) => {
2526
const handleOnClick = useNavigateToAppEventHandler(appId, { path, state, onClick });
2627
return (
27-
// @ts-ignore
2828
// eslint-disable-next-line @elastic/eui/href-or-on-click
29-
<EuiLink {...otherProps} href={'#'} onClick={handleOnClick}>
29+
<EuiLink {...otherProps} onClick={handleOnClick}>
3030
{children}
3131
</EuiLink>
3232
);

x-pack/plugins/endpoint/public/applications/endpoint/hooks/use_navigate_to_app_event_handler.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,12 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

7-
import { useCallback } from 'react';
7+
import { MouseEventHandler, useCallback } from 'react';
88
import { ApplicationStart } from 'kibana/public';
9-
import { EuiLinkProps } from '@elastic/eui';
109
import { useKibana } from '../../../../../../../src/plugins/kibana_react/public';
1110

1211
type NavigateToAppHandlerProps = Parameters<ApplicationStart['navigateToApp']>;
13-
type EventHandlerCallback = EuiLinkProps['onClick'];
12+
type EventHandlerCallback = MouseEventHandler<HTMLButtonElement | HTMLAnchorElement>;
1413

1514
/**
1615
* Provides an event handlers that can be used with (for example) `onClick` to prevent the
@@ -52,6 +51,18 @@ export const useNavigateToAppEventHandler = (
5251
return;
5352
}
5453

54+
if (ev.button !== 0) {
55+
return;
56+
}
57+
58+
if (
59+
ev.currentTarget instanceof HTMLAnchorElement &&
60+
ev.currentTarget.target !== '' &&
61+
ev.currentTarget.target !== '_self'
62+
) {
63+
return;
64+
}
65+
5566
if (ev.metaKey || ev.altKey || ev.ctrlKey || ev.shiftKey) {
5667
return;
5768
}

0 commit comments

Comments
 (0)