Skip to content
Open
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
6 changes: 6 additions & 0 deletions .changeset/time-picker-dismiss.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@hyperdx/app': patch
---

fix: close the time picker on a click outside it or on Escape. It stayed open,
including above the row side panel opened by clicking a search result.
6 changes: 5 additions & 1 deletion packages/app/src/components/TimePicker/TimePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,11 @@ const TimePickerComponent = ({
position="bottom-start"
closeOnEscape
opened={opened}
onClose={close}
// A controlled popover reports outside clicks and Escape (closeOnEscape)
// only through onChange; onClose fires after `opened` is already false.
onChange={next => {
Comment thread
drewhammond marked this conversation as resolved.
Resolved

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 P2 — Escape in a nested dropdown (Duration ±, time zone select, date calendar) now closes the whole picker and loses unapplied edits

Mantine's Popover.Dropdown handles closeOnEscape in onKeyDownCapture. The Duration Select, TimePickerTimeZoneSelect and the DateInputCmp popovers are all portaled into containerRef, which is inside this dropdown, so the outer handler sees their Escape first. Before this change the outer handler did nothing because onChange wasn't passed. Now it calls close(). Repro: open the picker, edit Start time, open the Duration or time zone dropdown, then press Escape to dismiss that dropdown. The whole picker closes, and the !opened effect at line 178 resets the form from dateRange, so the edits are lost. Fix: in onChange, ignore Escape that came from a nested combobox or popover, e.g. skip the close when containerRef contains an open [data-combobox-dropdown] or popover dropdown, or track the nested dropdowns' open state. Add a test that presses Escape inside the open Duration select and asserts that time-picker-popover stays mounted.

Advisory. Fix if it is a small defect in code this PR changes; otherwise reply in the thread. Do not widen the PR or touch files it did not already change. How to respond

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't fix: I think this is the expected behavior. It matches what clicking outside the picker or the X button does, and all three discard unapplied edits the same way.

if (!next) close();
}}
zIndex={getDefaultZIndex('popover') + 2}
>
<Popover.Target>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { fireEvent, screen } from '@testing-library/react';
import { fireEvent, screen, waitFor } from '@testing-library/react';

import { TimePicker } from '@/components/TimePicker';

Expand Down Expand Up @@ -76,3 +76,40 @@ describe('TimePicker time zone', () => {
);
});
});

describe('TimePicker dismissal', () => {
it.each([
[
'a click outside it',
() => fireEvent.mouseDown(screen.getByText('Outside')),
],
[
'Escape',
() =>
fireEvent.keyDown(screen.getByTestId('time-picker-popover'), {
key: 'Escape',
}),
],
])('closes on %s', async (_, dismiss) => {
renderWithMantine(
<>
<button>Outside</button>
<TimePicker
inputValue="Last 1 hour"
setInputValue={jest.fn()}
onSearch={jest.fn()}
/>
</>,
);
fireEvent.click(screen.getByTestId('time-picker-input'));
await screen.findByTestId('time-picker-popover');

dismiss();

await waitFor(() =>
expect(
screen.queryByTestId('time-picker-popover'),
).not.toBeInTheDocument(),
);
});
});
Loading