-
Notifications
You must be signed in to change notification settings - Fork 439
feat(app): close search & session drawers on outside click #2682
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
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
642609d
feat(app): close search & session drawers on outside click
elizabetdev fbdc096
refactor(app): default closeOnClickOutside to true for row-table drawers
elizabetdev 0bb09fa
fix(app): scope role="grid" match to Mantine calendars in useCloseOnC…
elizabetdev 0031d7e
fix: only close row side panel on outside click at root level
elizabetdev 3f6af74
Merge branch 'main' into elizabet/close-drawer-on-outside-click
elizabetdev f1806be
Merge branch 'main' into elizabet/close-drawer-on-outside-click
elizabetdev 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| --- | ||
| '@hyperdx/app': patch | ||
| --- | ||
|
|
||
| Detail drawers now close when you click outside of them. On Search and Sessions, | ||
| clicking outside the results table / session list dismisses the open drawer; | ||
| clicks inside the drawer, its nested popups/modals, or the results table keep it | ||
| open. This is on by default for row-table side panels (opt out with | ||
| `closeOnClickOutside={false}`). |
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
91 changes: 91 additions & 0 deletions
91
packages/app/src/hooks/__tests__/useCloseOnClickOutside.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,91 @@ | ||
| import { act, renderHook } from '@testing-library/react'; | ||
|
|
||
| import { useCloseOnClickOutside } from '@/hooks/useCloseOnClickOutside'; | ||
|
|
||
| function mouseDownOn(el: Element) { | ||
| act(() => { | ||
| el.dispatchEvent( | ||
| new MouseEvent('mousedown', { bubbles: true, cancelable: true }), | ||
| ); | ||
| }); | ||
| } | ||
|
|
||
| describe('useCloseOnClickOutside', () => { | ||
| afterEach(() => { | ||
| document.body.innerHTML = ''; | ||
| }); | ||
|
|
||
| it('closes when clicking a plain element outside the safe zones', () => { | ||
| const outside = document.createElement('div'); | ||
| document.body.appendChild(outside); | ||
|
|
||
| const onClose = jest.fn(); | ||
| renderHook(() => useCloseOnClickOutside({ enabled: true, onClose })); | ||
|
|
||
| mouseDownOn(outside); | ||
| expect(onClose).toHaveBeenCalledTimes(1); | ||
| }); | ||
|
|
||
| it('does not close when clicking inside the keepOpen selector', () => { | ||
| const table = document.createElement('div'); | ||
| table.setAttribute('data-testid', 'results'); | ||
| const cell = document.createElement('span'); | ||
| table.appendChild(cell); | ||
| document.body.appendChild(table); | ||
|
|
||
| const onClose = jest.fn(); | ||
| renderHook(() => | ||
| useCloseOnClickOutside({ | ||
| enabled: true, | ||
| keepOpenSelector: '[data-testid="results"]', | ||
| onClose, | ||
| }), | ||
| ); | ||
|
|
||
| mouseDownOn(cell); | ||
| expect(onClose).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it('does not close when clicking inside a floating layer (dialog/dropdown)', () => { | ||
| const dialog = document.createElement('div'); | ||
| dialog.setAttribute('role', 'dialog'); | ||
| const dialogChild = document.createElement('button'); | ||
| dialog.appendChild(dialogChild); | ||
|
|
||
| const dropdown = document.createElement('div'); | ||
| dropdown.className = 'mantine-Select-dropdown'; | ||
| const option = document.createElement('div'); | ||
| dropdown.appendChild(option); | ||
|
|
||
| document.body.append(dialog, dropdown); | ||
|
|
||
| const onClose = jest.fn(); | ||
| renderHook(() => useCloseOnClickOutside({ enabled: true, onClose })); | ||
|
|
||
| mouseDownOn(dialogChild); | ||
| mouseDownOn(option); | ||
| expect(onClose).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it('does nothing while disabled and detaches its listener on cleanup', () => { | ||
| const outside = document.createElement('div'); | ||
| document.body.appendChild(outside); | ||
|
|
||
| const onClose = jest.fn(); | ||
| const { rerender, unmount } = renderHook( | ||
| ({ enabled }) => useCloseOnClickOutside({ enabled, onClose }), | ||
| { initialProps: { enabled: false } }, | ||
| ); | ||
|
|
||
| mouseDownOn(outside); | ||
| expect(onClose).not.toHaveBeenCalled(); | ||
|
|
||
| rerender({ enabled: true }); | ||
| mouseDownOn(outside); | ||
| expect(onClose).toHaveBeenCalledTimes(1); | ||
|
|
||
| unmount(); | ||
| mouseDownOn(outside); | ||
| expect(onClose).toHaveBeenCalledTimes(1); | ||
| }); | ||
| }); |
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.
Uh oh!
There was an error while loading. Please reload this page.