Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Discover][DocViewer] Fix keyboard events in search input #180022

Merged
merged 2 commits into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,21 @@ describe('Discover flyout', function () {
expect(props.setExpandedDoc).not.toHaveBeenCalled();
});

it('should not navigate with arrow keys through documents if an input is in focus', async () => {
mockFlyoutCustomization.Content = () => {
return <input data-test-subj="flyoutCustomInput" />;
};

const { component, props } = await mountComponent({});
findTestSubject(component, 'flyoutCustomInput').simulate('keydown', {
key: 'ArrowRight',
});
findTestSubject(component, 'flyoutCustomInput').simulate('keydown', {
key: 'ArrowLeft',
});
expect(props.setExpandedDoc).not.toHaveBeenCalled();
});

it('should not render single/surrounding views for text based', async () => {
const { component } = await mountComponent({
query: { esql: 'FROM indexpattern' },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/

import React, { useMemo, useCallback } from 'react';
import { get } from 'lodash';
import { i18n } from '@kbn/i18n';
import { css } from '@emotion/react';
import type { DataView } from '@kbn/data-views-plugin/public';
Expand Down Expand Up @@ -99,6 +100,10 @@ export function DiscoverGridFlyout({

const onKeyDown = useCallback(
(ev: React.KeyboardEvent) => {
const nodeName = get(ev, 'target.nodeName', null);
if (typeof nodeName === 'string' && nodeName.toLowerCase() === 'input') {
return;
}
if (ev.key === keys.ARROW_LEFT || ev.key === keys.ARROW_RIGHT) {
ev.preventDefault();
ev.stopPropagation();
Expand Down