Skip to content

Commit 45ed003

Browse files
author
Tim Roes
authored
Allow navigating discover flyout via arrow keys (#101772)
1 parent 144e014 commit 45ed003

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

src/plugins/discover/public/application/components/discover_grid/discover_grid_flyout.test.tsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,4 +143,24 @@ describe('Discover flyout', function () {
143143
expect(props.setExpandedDoc).toHaveBeenCalledTimes(1);
144144
expect(props.setExpandedDoc.mock.calls[0][0]._id).toBe('4');
145145
});
146+
147+
it('allows navigating with arrow keys through documents', () => {
148+
const props = getProps();
149+
const component = mountWithIntl(<DiscoverGridFlyout {...props} />);
150+
findTestSubject(component, 'docTableDetailsFlyout').simulate('keydown', { key: 'ArrowRight' });
151+
expect(props.setExpandedDoc).toHaveBeenCalledWith(expect.objectContaining({ _id: '2' }));
152+
component.setProps({ ...props, hit: props.hits[1] });
153+
findTestSubject(component, 'docTableDetailsFlyout').simulate('keydown', { key: 'ArrowLeft' });
154+
expect(props.setExpandedDoc).toHaveBeenCalledWith(expect.objectContaining({ _id: '1' }));
155+
});
156+
157+
it('should not navigate with keypresses when already at the border of documents', () => {
158+
const props = getProps();
159+
const component = mountWithIntl(<DiscoverGridFlyout {...props} />);
160+
findTestSubject(component, 'docTableDetailsFlyout').simulate('keydown', { key: 'ArrowLeft' });
161+
expect(props.setExpandedDoc).not.toHaveBeenCalled();
162+
component.setProps({ ...props, hit: props.hits[props.hits.length - 1] });
163+
findTestSubject(component, 'docTableDetailsFlyout').simulate('keydown', { key: 'ArrowRight' });
164+
expect(props.setExpandedDoc).not.toHaveBeenCalled();
165+
});
146166
});

src/plugins/discover/public/application/components/discover_grid/discover_grid_flyout.tsx

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
EuiPortal,
2222
EuiPagination,
2323
EuiHideFor,
24+
keys,
2425
} from '@elastic/eui';
2526
import { DocViewer } from '../doc_viewer/doc_viewer';
2627
import { IndexPattern } from '../../../kibana_services';
@@ -87,9 +88,25 @@ export function DiscoverGridFlyout({
8788
[hits, setExpandedDoc]
8889
);
8990

91+
const onKeyDown = useCallback(
92+
(ev: React.KeyboardEvent) => {
93+
if (ev.key === keys.ARROW_LEFT || ev.key === keys.ARROW_RIGHT) {
94+
ev.preventDefault();
95+
ev.stopPropagation();
96+
setPage(activePage + (ev.key === keys.ARROW_RIGHT ? 1 : -1));
97+
}
98+
},
99+
[activePage, setPage]
100+
);
101+
90102
return (
91103
<EuiPortal>
92-
<EuiFlyout onClose={onClose} size="m" data-test-subj="docTableDetailsFlyout">
104+
<EuiFlyout
105+
onClose={onClose}
106+
size="m"
107+
data-test-subj="docTableDetailsFlyout"
108+
onKeyDown={onKeyDown}
109+
>
93110
<EuiFlyoutHeader hasBorder>
94111
<EuiTitle
95112
size="s"

0 commit comments

Comments
 (0)