Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1065,7 +1065,6 @@ Array [
/>
<div
class="euiPopover euiPopover--anchorDownCenter eui-fullWidth"
offset="7"
>
<div
class="euiPopover__anchor eui-fullWidth"
Expand Down Expand Up @@ -1109,7 +1108,6 @@ Array [
/>
<div
class="euiPopover euiPopover--anchorDownCenter eui-fullWidth"
offset="7"
>
<div
class="euiPopover__anchor eui-fullWidth"
Expand Down Expand Up @@ -1506,7 +1504,6 @@ Array [
/>
<div
class="euiPopover euiPopover--anchorDownCenter eui-fullWidth"
offset="7"
>
<div
class="euiPopover__anchor eui-fullWidth"
Expand Down Expand Up @@ -1550,7 +1547,6 @@ Array [
/>
<div
class="euiPopover euiPopover--anchorDownCenter eui-fullWidth"
offset="7"
>
<div
class="euiPopover__anchor eui-fullWidth"
Expand Down Expand Up @@ -2244,7 +2240,6 @@ Array [
/>
<div
class="euiPopover euiPopover--anchorDownCenter eui-fullWidth"
offset="7"
>
<div
class="euiPopover__anchor eui-fullWidth"
Expand Down Expand Up @@ -2288,7 +2283,6 @@ Array [
/>
<div
class="euiPopover euiPopover--anchorDownCenter eui-fullWidth"
offset="7"
>
<div
class="euiPopover__anchor eui-fullWidth"
Expand Down Expand Up @@ -2665,7 +2659,6 @@ Array [
/>
<div
class="euiPopover euiPopover--anchorDownCenter eui-fullWidth"
offset="7"
>
<div
class="euiPopover__anchor eui-fullWidth"
Expand Down Expand Up @@ -2709,7 +2702,6 @@ Array [
/>
<div
class="euiPopover euiPopover--anchorDownCenter eui-fullWidth"
offset="7"
>
<div
class="euiPopover__anchor eui-fullWidth"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ exports[`EuiDataGridBody renders 1`] = `
/>
<div
class="euiPopover euiPopover--anchorDownCenter eui-fullWidth"
offset="7"
>
<div
class="euiPopover__anchor eui-fullWidth"
Expand Down Expand Up @@ -75,7 +74,6 @@ exports[`EuiDataGridBody renders 1`] = `
/>
<div
class="euiPopover euiPopover--anchorDownCenter eui-fullWidth"
offset="7"
>
<div
class="euiPopover__anchor eui-fullWidth"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,49 +45,59 @@ exports[`EuiDataGridHeaderCell renders 1`] = `
offset={7}
ownFocus={true}
panelPaddingSize="none"
>
<div>
<EuiListGroup
data-test-subj="dataGridHeaderCellActionGroup-someColumn"
gutterSize="none"
listItems={
Array [
Object {
"color": "text",
"iconType": "eyeClosed",
"label": <EuiI18n
default="Hide column"
token="euiColumnActions.hideColumn"
/>,
"onClick": [Function],
"size": "xs",
},
Object {
"color": "text",
"iconType": "sortLeft",
"isDisabled": false,
"label": <EuiI18n
default="Move left"
token="euiColumnActions.moveLeft"
/>,
"onClick": [Function],
"size": "xs",
},
Object {
"color": "text",
"iconType": "sortRight",
"isDisabled": true,
"label": <EuiI18n
default="Move right"
token="euiColumnActions.moveRight"
/>,
"onClick": [Function],
"size": "xs",
},
]
}
panelProps={
Object {
"onKeyDown": [Function],
}
}
panelRef={[Function]}
popoverScreenReaderText={
<EuiI18n
default="To navigate through the list of column actions, press the Tab or Up and Down arrow keys."
token="euiDataGridHeaderCell.actionsPopoverScreenReaderText"
/>
</div>
}
>
<EuiListGroup
data-test-subj="dataGridHeaderCellActionGroup-someColumn"
gutterSize="none"
listItems={
Array [
Object {
"color": "text",
"iconType": "eyeClosed",
"label": <EuiI18n
default="Hide column"
token="euiColumnActions.hideColumn"
/>,
"onClick": [Function],
"size": "xs",
},
Object {
"color": "text",
"iconType": "sortLeft",
"isDisabled": false,
"label": <EuiI18n
default="Move left"
token="euiColumnActions.moveLeft"
/>,
"onClick": [Function],
"size": "xs",
},
Object {
"color": "text",
"iconType": "sortRight",
"isDisabled": true,
"label": <EuiI18n
default="Move right"
token="euiColumnActions.moveRight"
/>,
"onClick": [Function],
"size": "xs",
},
]
}
/>
</EuiPopover>
</EuiDataGridHeaderCellWrapper>
`;
115 changes: 114 additions & 1 deletion src/components/datagrid/body/header/data_grid_header_cell.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,17 @@

import React from 'react';
import { mount, shallow } from 'enzyme';
import { testCustomHook } from '../../../../test/internal';

import { EuiDataGridSorting } from '../../data_grid_types';
import { DataGridSortingContext } from '../../utils/sorting';
import { DataGridFocusContext } from '../../utils/focus';
import { mockFocusContext } from '../../utils/__mocks__/focus_context';

import { EuiDataGridHeaderCell } from './data_grid_header_cell';
import {
EuiDataGridHeaderCell,
usePopoverArrowNavigation,
} from './data_grid_header_cell';

describe('EuiDataGridHeaderCell', () => {
const requiredProps = {
Expand Down Expand Up @@ -164,5 +168,114 @@ describe('EuiDataGridHeaderCell', () => {

expect(component.find('EuiPopover').prop('isOpen')).toEqual(false);
});

describe('keyboard arrow navigation', () => {
const {
return: {
panelRef,
panelProps: { onKeyDown },
},
} = testCustomHook(usePopoverArrowNavigation);

const mockPanel = document.createElement('div');
mockPanel.setAttribute('tabindex', '-1');
mockPanel.innerHTML = `
<button data-test-subj="first">First action</button>
<button data-test-subj="second">Second action</button>
<button data-test-subj="last">Last action</button>
`;
panelRef(mockPanel);

const preventDefault = jest.fn();
beforeEach(() => jest.clearAllMocks());

describe('early returns', () => {
it('does nothing if the up/down arrow keys are not pressed', () => {
onKeyDown({ key: 'Tab', preventDefault });
expect(preventDefault).not.toHaveBeenCalled();
});

it('does nothing if the popover contains no tabbable elements', () => {
const emptyDiv = document.createElement('div');
panelRef(emptyDiv);
onKeyDown({ key: 'ArrowDown', preventDefault });
expect(preventDefault).not.toHaveBeenCalled();

panelRef(mockPanel); // Reset for other tests
});
});

describe('when the popover panel is focused (on initial open state)', () => {
beforeEach(() => mockPanel.focus());

it('focuses the first action when the arrow down key is pressed', () => {
onKeyDown({ key: 'ArrowDown', preventDefault });
expect(preventDefault).toHaveBeenCalled();
expect(
document.activeElement?.getAttribute('data-test-subj')
).toEqual('first');
});

it('focuses the last action when the arrow up key is pressed', () => {
onKeyDown({ key: 'ArrowUp', preventDefault });
expect(preventDefault).toHaveBeenCalled();
expect(
document.activeElement?.getAttribute('data-test-subj')
).toEqual('last');
});
});

describe('when already focused on action buttons', () => {
describe('down arrow key', () => {
beforeAll(() =>
(mockPanel.firstElementChild as HTMLButtonElement).focus()
);

it('moves focus to the the next action', () => {
onKeyDown({ key: 'ArrowDown', preventDefault });
expect(
document.activeElement?.getAttribute('data-test-subj')
).toEqual('second');

onKeyDown({ key: 'ArrowDown', preventDefault });
expect(
document.activeElement?.getAttribute('data-test-subj')
).toEqual('last');
});

it('loops focus back to the first action when pressing down on the last action', () => {
onKeyDown({ key: 'ArrowDown', preventDefault });
expect(
document.activeElement?.getAttribute('data-test-subj')
).toEqual('first');
});
});

describe('up arrow key', () => {
beforeAll(() =>
(mockPanel.lastElementChild as HTMLButtonElement).focus()
);

it('moves focus to the previous action', () => {
onKeyDown({ key: 'ArrowUp', preventDefault });
expect(
document.activeElement?.getAttribute('data-test-subj')
).toEqual('second');

onKeyDown({ key: 'ArrowUp', preventDefault });
expect(
document.activeElement?.getAttribute('data-test-subj')
).toEqual('first');
});

it('loops focus back to the last action when pressing up on the first action', () => {
onKeyDown({ key: 'ArrowUp', preventDefault });
expect(
document.activeElement?.getAttribute('data-test-subj')
).toEqual('last');
});
});
});
});
});
});
Loading