-
Notifications
You must be signed in to change notification settings - Fork 8.4k
[kbn-grid-layout][dashboard] Basic keyboard interaction #208286
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
Merged
mbondyra
merged 35 commits into
elastic:main
from
mbondyra:collapsable_panels/keyboard_navigation
Apr 1, 2025
Merged
Changes from all commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
4367286
[Collapsable Panels] [Dashboard] basic keyboard interaction
mbondyra aa2d0ec
wip
mbondyra 450f62c
wip
mbondyra 48e8dcf
wip
mbondyra 45b475b
add tests
mbondyra dc1abf2
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine 3caed27
revert the naming
mbondyra e9fce28
Merge commit 'dc1abf24337882bffb7d9e4bfd643d45cdeb4637' into keyboard…
mbondyra 1a6442e
Merge commit 'e7bc3b5a933942d50c543079c2de53eda0453ac8' into keyboard…
mbondyra af05298
missing pieces
mbondyra 08f9e3b
Merge branch 'presentation_scss_migration' into keyboard_temp
mbondyra 10d85d7
CR
mbondyra 8acdb22
CR
mbondyra 55e9882
wip
mbondyra ff0f777
fix types
mbondyra 616aadb
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine 238e447
Merge branch 'presentation_scss_migration' into collapsable_panels/ke…
mbondyra 8c31f26
last CR corrections
mbondyra c178111
activePanel on start so the boundaries are well calculated
mbondyra 524784c
refactor to remove activePanel observable
mbondyra 76ce946
remove var
mbondyra ca2ba8e
wip
mbondyra e786cc5
[CI] Auto-commit changed files from 'node scripts/notice'
kibanamachine d050775
wip
mbondyra 8a77216
Merge branch 'collapsable_panels/keyboard_navigation' of github.com:m…
mbondyra 8bc22ef
Merge commit 'f699e4ec2097ecaf0bc1f099cfd65092dfc316b4' into collapsa…
mbondyra b1d12a0
Merge branch 'dashboard/no_geometry_change' into collapsable_panels/k…
mbondyra 58b068e
fix not able to click on the time range
mbondyra 51b06af
fix tests
mbondyra 5c82a1c
Revert "fix not able to click on the time range"
mbondyra 2550004
Revert "fix tests"
mbondyra f840a22
Revert "remove var"
mbondyra a79e08f
Revert "refactor to remove activePanel observable"
mbondyra 02f7d31
revert one more
mbondyra 20726ff
Merge branch 'main' into collapsable_panels/keyboard_navigation
mbondyra File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
src/platform/packages/private/kbn-grid-layout/grid/keyboard_navigation.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the "Elastic License | ||
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
* Public License v 1"; you may not use this file except in compliance with, at | ||
* your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
import React from 'react'; | ||
import { render, screen, within } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
import { getSampleLayout } from './test_utils/sample_layout'; | ||
import { GridLayout, GridLayoutProps } from './grid_layout'; | ||
import { gridSettings, mockRenderPanelContents } from './test_utils/mocks'; | ||
import { EuiThemeProvider } from '@elastic/eui'; | ||
|
||
const onLayoutChange = jest.fn(); | ||
|
||
const renderGridLayout = (propsOverrides: Partial<GridLayoutProps> = {}) => { | ||
const props = { | ||
accessMode: 'EDIT', | ||
layout: getSampleLayout(), | ||
gridSettings, | ||
renderPanelContents: mockRenderPanelContents, | ||
onLayoutChange, | ||
...propsOverrides, | ||
} as GridLayoutProps; | ||
|
||
const { rerender, ...rtlRest } = render(<GridLayout {...props} />, { wrapper: EuiThemeProvider }); | ||
|
||
return { | ||
...rtlRest, | ||
rerender: (overrides: Partial<GridLayoutProps>) => { | ||
const newProps = { ...props, ...overrides } as GridLayoutProps; | ||
return rerender(<GridLayout {...newProps} />); | ||
}, | ||
}; | ||
}; | ||
|
||
const getPanelHandle = (panelId: string, interactionType: 'resize' | 'drag' = 'drag') => { | ||
const gridPanel = screen.getByText(`panel content ${panelId}`).closest('div')!; | ||
const handleText = new RegExp(interactionType === 'resize' ? /resize panel/i : /drag to move/i); | ||
return within(gridPanel).getByRole('button', { name: handleText }); | ||
}; | ||
|
||
describe('Keyboard navigation', () => { | ||
window.HTMLElement.prototype.scrollIntoView = jest.fn(); | ||
Object.defineProperty(window, 'scrollY', { value: 0, writable: false }); | ||
Object.defineProperty(document.body, 'scrollHeight', { value: 2000, writable: false }); | ||
|
||
const pressEnter = async () => { | ||
await userEvent.keyboard('[Enter]'); | ||
}; | ||
const pressKey = async ( | ||
k: '[Enter]' | '{Escape}' | '[ArrowDown]' | '[ArrowUp]' | '[ArrowRight]' | '[ArrowLeft]' | ||
) => { | ||
await userEvent.keyboard(k); | ||
}; | ||
it('should show the panel active when during interaction for drag handle', async () => { | ||
renderGridLayout(); | ||
const panelHandle = getPanelHandle('panel1'); | ||
panelHandle.focus(); | ||
expect(screen.getByLabelText('panelId:panel1').closest('div')).toHaveClass('kbnGridPanel', { | ||
exact: true, | ||
}); | ||
await pressEnter(); | ||
await pressKey('[ArrowDown]'); | ||
expect(panelHandle).toHaveFocus(); // focus is not lost during interaction | ||
expect(screen.getByLabelText('panelId:panel1').closest('div')).toHaveClass( | ||
'kbnGridPanel kbnGridPanel--active', | ||
{ exact: true } | ||
); | ||
await pressEnter(); | ||
expect(screen.getByLabelText('panelId:panel1').closest('div')).toHaveClass('kbnGridPanel', { | ||
exact: true, | ||
}); | ||
}); | ||
it('should show the panel active when during interaction for resize handle', async () => { | ||
renderGridLayout(); | ||
const panelHandle = getPanelHandle('panel5', 'resize'); | ||
panelHandle.focus(); | ||
expect(screen.getByLabelText('panelId:panel5').closest('div')).toHaveClass('kbnGridPanel', { | ||
exact: true, | ||
}); | ||
await pressEnter(); | ||
await pressKey('[ArrowDown]'); | ||
expect(panelHandle).toHaveFocus(); // focus is not lost during interaction | ||
expect(screen.getByLabelText('panelId:panel5').closest('div')).toHaveClass( | ||
'kbnGridPanel kbnGridPanel--active', | ||
{ exact: true } | ||
); | ||
await pressKey('{Escape}'); | ||
expect(screen.getByLabelText('panelId:panel5').closest('div')).toHaveClass('kbnGridPanel', { | ||
exact: true, | ||
}); | ||
expect(panelHandle).toHaveFocus(); // focus is not lost during interaction | ||
}); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
src/platform/packages/private/kbn-grid-layout/grid/use_grid_layout_events/keyboard_utils.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the "Elastic License | ||
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
* Public License v 1"; you may not use this file except in compliance with, at | ||
* your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
|
||
export const updateClientY = ( | ||
currentY: number, | ||
stepY: number, | ||
isCloseToEdge: boolean, | ||
type = 'drag' | ||
) => { | ||
if (isCloseToEdge) { | ||
switch (type) { | ||
case 'drag': | ||
window.scrollTo({ top: window.scrollY + stepY, behavior: 'smooth' }); | ||
return currentY; | ||
case 'resize': | ||
setTimeout(() => | ||
document.activeElement?.scrollIntoView({ behavior: 'smooth', block: 'end' }) | ||
); | ||
} | ||
} | ||
return currentY + stepY; | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This offset defines how much maximum up we want to drag the element in keyboard mode. For a natural appearance, it should be around the height of the fixed header, which is different from the grid's top position due to the content that can be before it, but not be fixed (like scrollable controls in case of dashboard). I think the best option is to keep it as a prop.