Skip to content

Commit df55627

Browse files
flash1293bhavyarm
andauthored
Fix special click behavior in new side nav (#214650)
Not sure whether we have an issue for is, but a problem I constantly run into is that cmd+click to open in new tab doesn't work with the new side nav. You need to do right click + open in new tab which is taking at least 3 times as long. This is a problem because it's not the expected behavior - the entries in the nav are regular links and they should behave like that (the old nav didn't have this problem). This PR fixes the issue to not call `e.preventDefault()` in case it's a "special click" and only triggers the in-page navigation in cases where the user does a normal left click. Co-authored-by: Bhavya RM <[email protected]>
1 parent b9d240b commit df55627

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/platform/packages/shared/shared-ux/chrome/navigation/src/ui/components/navigation_section_ui.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,16 @@ const getEuiProps = (
283283
})
284284
.flat();
285285

286+
/**
287+
* Check if the click event is a special click (e.g. right click, click with modifier key)
288+
* We do not want to prevent the default behavior in these cases.
289+
*/
290+
const isSpecialClick = (e: React.MouseEvent<HTMLElement | HTMLButtonElement>) => {
291+
const isModifiedEvent = !!(e.metaKey || e.altKey || e.ctrlKey || e.shiftKey);
292+
const isLeftClickEvent = e.button === 0;
293+
return isModifiedEvent || !isLeftClickEvent;
294+
};
295+
286296
const linkProps: EuiCollapsibleNavItemProps['linkProps'] | undefined = hasLink
287297
? {
288298
href,
@@ -301,6 +311,10 @@ const getEuiProps = (
301311
return;
302312
}
303313

314+
if (isSpecialClick(e)) {
315+
return;
316+
}
317+
304318
if (href) {
305319
e.preventDefault();
306320
navigateToUrl(href);
@@ -327,6 +341,10 @@ const getEuiProps = (
327341
// will be used in the breadcrumb navigation.
328342
if (isAccordion && isCollapsible) return;
329343

344+
if (isSpecialClick(e)) {
345+
return;
346+
}
347+
330348
if (href !== undefined) {
331349
e.preventDefault();
332350
navigateToUrl(href);

0 commit comments

Comments
 (0)