grafana-ui: prevent TimeRangePicker from submitting wrapping forms (#97973)

This commit is contained in:
Russ 2025-01-02 08:31:12 -09:00 committed by GitHub
parent 1a6312296e
commit 0e55e45f88
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 26 additions and 0 deletions

View File

@ -91,3 +91,25 @@ describe('TimePicker', () => {
expect(unsyncButtons.length).toBe(2);
});
});
it('does not submit wrapping forms', async () => {
const onSubmit = jest.fn();
const container = render(
<form onSubmit={onSubmit}>
<TimeRangePicker
onChangeTimeZone={() => {}}
onChange={(value) => {}}
value={value}
onMoveBackward={() => {}}
onMoveForward={() => {}}
onZoom={() => {}}
/>
</form>
);
const clicks = container.getAllByRole('button').map((button) => userEvent.click(button));
await Promise.all(clicks);
expect(onSubmit).not.toHaveBeenCalled();
});

View File

@ -149,6 +149,7 @@ export function TimeRangePicker(props: TimeRangePickerProps) {
variant={variant}
onClick={onMoveBackward}
icon="angle-left"
type="button"
narrow
/>
)}
@ -168,6 +169,7 @@ export function TimeRangePicker(props: TimeRangePickerProps) {
onClick={onToolbarButtonSwitch}
icon={timePickerIcon}
isOpen={isOpen}
type="button"
variant={variant}
>
<TimePickerButtonLabel {...props} />
@ -206,6 +208,7 @@ export function TimeRangePicker(props: TimeRangePickerProps) {
onClick={onMoveForward}
icon="angle-right"
narrow
type="button"
variant={variant}
/>
)}
@ -215,6 +218,7 @@ export function TimeRangePicker(props: TimeRangePickerProps) {
aria-label={t('time-picker.range-picker.zoom-out-button', 'Zoom out time range')}
onClick={onZoom}
icon="search-minus"
type="button"
variant={variant}
/>
</Tooltip>