Repository navigation
feat(healthcheck): support opt-in non-modal drawers #4449
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
Open
astandrik
wants to merge
6
commits into
main
Choose a base branch
from
fix/healthcheck-non-modal-4440
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,054
−197
Open
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
1fdc548
feat(healthcheck): support opt-in non-modal drawers
astandrik cb59507
fix(drawer): preserve veil click dismissal
astandrik 59a9fca
test: adapt error checks to uikit 7.48
astandrik 49ebc43
test(healthcheck): trim duplicate drawer coverage
astandrik cfcc9b9
fix: restore focus to healthcheck opener in non-modal mode
astandrik 8b4a549
test: stabilize diagnostics and nodes checks
astandrik 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -75,7 +75,8 @@ | |
|
|
||
| height: 100%; | ||
| } | ||
| &__click-handler { | ||
| &__click-handler, | ||
| &__event-boundary { | ||
| display: contents; | ||
| } | ||
| } | ||
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
99 changes: 99 additions & 0 deletions
99
src/components/Drawer/__test__/DrawerAccessibility.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,99 @@ | ||
| import React from 'react'; | ||
|
|
||
| import {Drawer, ThemeProvider} from '@gravity-ui/uikit'; | ||
| import {fireEvent, render, screen, waitFor, within} from '@testing-library/react'; | ||
|
|
||
| import {DrawerWrapper} from '../Drawer'; | ||
| import {DrawerContextProvider} from '../DrawerContext'; | ||
|
|
||
| jest.mock('../../../utils/hooks/useSetting', () => ({ | ||
| useSetting: () => [undefined, jest.fn()], | ||
| })); | ||
|
|
||
| function Fixture() { | ||
| const [healthcheck, setHealthcheck] = React.useState(false); | ||
| const [assistant, setAssistant] = React.useState(false); | ||
| return ( | ||
| <ThemeProvider theme="light"> | ||
| <DrawerContextProvider> | ||
| <DrawerWrapper | ||
| title="Healthcheck" | ||
| isDrawerVisible={healthcheck} | ||
| onCloseDrawer={() => setHealthcheck(false)} | ||
| drawerControls={[{type: 'close'}]} | ||
| disableModal | ||
| renderDrawerContent={() => <input aria-label="Healthcheck filter" />} | ||
| > | ||
| <button onClick={() => setHealthcheck(true)}>Open Healthcheck</button> | ||
| <button onClick={() => setAssistant(true)}>Open assistant</button> | ||
| </DrawerWrapper> | ||
| </DrawerContextProvider> | ||
| <Drawer | ||
| open={assistant} | ||
| disableModal | ||
| hideVeil | ||
| aria-label="Assistant" | ||
| disableEscapeKeyDown | ||
| > | ||
| <button onClick={() => setAssistant(false)}>Close assistant</button> | ||
| </Drawer> | ||
| </ThemeProvider> | ||
| ); | ||
| } | ||
|
|
||
| const originalResizeObserver = window.ResizeObserver; | ||
| beforeEach(() => { | ||
| window.ResizeObserver = jest.fn(() => ({ | ||
| observe: jest.fn(), | ||
| unobserve: jest.fn(), | ||
| disconnect: jest.fn(), | ||
| })); | ||
| jest.spyOn(HTMLElement.prototype, 'getBoundingClientRect').mockReturnValue({ | ||
| x: 0, | ||
| y: 0, | ||
| top: 0, | ||
| left: 0, | ||
| width: 1400, | ||
| height: 800, | ||
| right: 1400, | ||
| bottom: 800, | ||
| toJSON() {}, | ||
| }); | ||
| }); | ||
| afterEach(() => { | ||
| window.ResizeObserver = originalResizeObserver; | ||
| jest.restoreAllMocks(); | ||
| }); | ||
|
|
||
| test('returns focus to its opener after visiting the adjacent panel', async () => { | ||
| render(<Fixture />); | ||
| const opener = screen.getByRole('button', {name: 'Open Healthcheck'}); | ||
| opener.focus(); | ||
| fireEvent.click(opener); | ||
| const healthcheck = await screen.findByRole('dialog', {name: 'Healthcheck'}); | ||
| const assistantOpener = screen.getByRole('button', {name: 'Open assistant'}); | ||
| assistantOpener.focus(); | ||
| fireEvent.click(assistantOpener); | ||
| await screen.findByRole('dialog', {name: 'Assistant'}); | ||
| within(healthcheck).getByRole('textbox').focus(); | ||
| fireEvent.keyDown(within(healthcheck).getByRole('textbox'), {key: 'Escape'}); | ||
| await waitFor(() => expect(opener).toHaveFocus()); | ||
| expect(screen.getByRole('dialog', {name: 'Assistant'})).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| test('does not steal focus from an adjacent panel when closed externally', async () => { | ||
| render(<Fixture />); | ||
| const opener = screen.getByRole('button', {name: 'Open Healthcheck'}); | ||
| opener.focus(); | ||
| fireEvent.click(opener); | ||
| const healthcheck = await screen.findByRole('dialog', {name: 'Healthcheck'}); | ||
| fireEvent.click(screen.getByRole('button', {name: 'Open assistant'})); | ||
| const assistantClose = await screen.findByRole('button', {name: 'Close assistant'}); | ||
| await waitFor(() => expect(screen.getByRole('dialog', {name: 'Assistant'})).toHaveFocus()); | ||
| assistantClose.focus(); | ||
| fireEvent.click(within(healthcheck).getByRole('button', {name: 'Close'})); | ||
| await waitFor(() => | ||
| expect(screen.queryByRole('dialog', {name: 'Healthcheck'})).not.toBeInTheDocument(), | ||
| ); | ||
| expect(assistantClose).toHaveFocus(); | ||
| }); |
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
Oops, something went wrong.
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.
When
disableModalis enabled in the cluster or database-list views on WebKit, a pointer click on a status button/interactive label does not move focus, so the layout effect records the previously focused element rather than the control that opened the drawer. The workaround inHealthcheckPreview.openHealthcheckcovers only tenant-page openers, whileCluster.tsxandDatabaseDrawerHealthcheck.tsxalso reach this globally configuredHealthcheckDrawer; closing those drawers therefore restores focus to the wrong element. Capture/pass the opener generically or apply the focus workaround to every healthcheck opener.AGENTS.md reference: AGENTS.md:L77-L77
Useful? React with 👍 / 👎.