Skip to content

Commit

Permalink
[Global Search] Fix cmd + click open in new tab for results (elastic#…
Browse files Browse the repository at this point in the history
…183762)

## Summary

Closes elastic#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
elastic/eui#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.
  • Loading branch information
rshen91 authored and rohanxz committed Jun 4, 2024
1 parent b3c3420 commit 440ff16
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -198,7 +199,7 @@ export const SearchBar: FC<SearchBarProps> = (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';
Expand Down Expand Up @@ -249,7 +250,13 @@ export const SearchBar: FC<SearchBarProps> = (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) {
Expand Down

0 comments on commit 440ff16

Please sign in to comment.