From 440ff166745cff5d1a31fd789cf8c7cce27f8637 Mon Sep 17 00:00:00 2001 From: Rachel Shen Date: Mon, 3 Jun 2024 16:41:16 -0600 Subject: [PATCH] [Global Search] Fix cmd + click open in new tab for results (#183762) ## Summary Closes https://github.com/elastic/kibana/issues/147710 This PR follows the pattern set up in https://github.com/elastic/kibana/blob/main/x-pack/plugins/spaces/public/nav_control/components/spaces_menu.tsx#L164-L170 to allow the cmd click behavior to work for kibana global search. I'm exploring contributing to the EUI repository in this https://github.com/elastic/eui/pull/7788 but that avenue may not be fruitful. This implementation is already being used in spaces and can immediately provide value for global search with this PR merge. --- .../public/components/search_bar.tsx | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/x-pack/plugins/global_search_bar/public/components/search_bar.tsx b/x-pack/plugins/global_search_bar/public/components/search_bar.tsx index 53f749fc3f7ad..04e519a83b534 100644 --- a/x-pack/plugins/global_search_bar/public/components/search_bar.tsx +++ b/x-pack/plugins/global_search_bar/public/components/search_bar.tsx @@ -18,6 +18,7 @@ import { euiSelectableTemplateSitewideRenderOptions, useEuiTheme, } from '@elastic/eui'; +import { EuiSelectableOnChangeEvent } from '@elastic/eui/src/components/selectable/selectable'; import { css } from '@emotion/react'; import type { GlobalSearchFindParams, GlobalSearchResult } from '@kbn/global-search-plugin/public'; import React, { FC, useCallback, useEffect, useRef, useState } from 'react'; @@ -198,7 +199,7 @@ export const SearchBar: FC = (opts) => { ); const onChange = useCallback( - (selection: EuiSelectableTemplateSitewideOption[]) => { + (selection: EuiSelectableTemplateSitewideOption[], event: EuiSelectableOnChangeEvent) => { let selectedRank: number | null = null; const selected = selection.find(({ checked }, rank) => { const isChecked = checked === 'on'; @@ -249,7 +250,13 @@ export const SearchBar: FC = (opts) => { console.log('Error trying to track searchbar metrics', err); } - navigateToUrl(url); + if (event.shiftKey) { + window.open(url); + } else if (event.ctrlKey || event.metaKey) { + window.open(url, '_blank'); + } else { + navigateToUrl(url); + } (document.activeElement as HTMLElement).blur(); if (searchRef) {