diff --git a/packages/grafana-ui/src/components/DateTimePickers/TimeRangePicker/TimePickerContent.tsx b/packages/grafana-ui/src/components/DateTimePickers/TimeRangePicker/TimePickerContent.tsx
index b0862fadf9f..88054a87072 100644
--- a/packages/grafana-ui/src/components/DateTimePickers/TimeRangePicker/TimePickerContent.tsx
+++ b/packages/grafana-ui/src/components/DateTimePickers/TimeRangePicker/TimePickerContent.tsx
@@ -12,7 +12,7 @@ import { Icon } from '../../Icon/Icon';
import { TimePickerFooter } from './TimePickerFooter';
import { TimePickerTitle } from './TimePickerTitle';
-import { TimeRangeForm } from './TimeRangeForm';
+import { TimeRangeContent } from './TimeRangeContent';
import { TimeRangeList } from './TimeRangeList';
import { mapOptionToTimeRange, mapRangeToTimeOption } from './mapper';
@@ -155,7 +155,7 @@ const NarrowScreenForm = (props: FormProps) => {
{!collapsed && (
-
+
{showHistory && (
= (props) => {
Absolute time range
- {}} timeZone={timeZone} />);
+ const result = render(
+ {}} timeZone={timeZone} />
+ );
return {
...result,
diff --git a/packages/grafana-ui/src/components/DateTimePickers/TimeRangePicker/TimeRangeForm.tsx b/packages/grafana-ui/src/components/DateTimePickers/TimeRangePicker/TimeRangeContent.tsx
similarity index 89%
rename from packages/grafana-ui/src/components/DateTimePickers/TimeRangePicker/TimeRangeForm.tsx
rename to packages/grafana-ui/src/components/DateTimePickers/TimeRangePicker/TimeRangeContent.tsx
index 64fad866e5c..4018c7e49c6 100644
--- a/packages/grafana-ui/src/components/DateTimePickers/TimeRangePicker/TimeRangeForm.tsx
+++ b/packages/grafana-ui/src/components/DateTimePickers/TimeRangePicker/TimeRangeContent.tsx
@@ -44,7 +44,7 @@ const ERROR_MESSAGES = {
range: '"From" can\'t be after "To"',
};
-export const TimeRangeForm = (props: Props) => {
+export const TimeRangeContent = (props: Props) => {
const { value, isFullscreen = false, timeZone, onApply: onApplyFromProps, isReversed, fiscalYearStartMonth } = props;
const [fromValue, toValue] = valueToState(value.raw.from, value.raw.to, timeZone);
const style = useStyles2(getStyles);
@@ -68,20 +68,16 @@ export const TimeRangeForm = (props: Props) => {
[setOpen]
);
- const onApply = useCallback(
- (e: FormEvent) => {
- e.preventDefault();
- if (to.invalid || from.invalid) {
- return;
- }
+ const onApply = useCallback(() => {
+ if (to.invalid || from.invalid) {
+ return;
+ }
- const raw: RawTimeRange = { from: from.value, to: to.value };
- const timeRange = rangeUtil.convertRawToRange(raw, timeZone, fiscalYearStartMonth);
+ const raw: RawTimeRange = { from: from.value, to: to.value };
+ const timeRange = rangeUtil.convertRawToRange(raw, timeZone, fiscalYearStartMonth);
- onApplyFromProps(timeRange);
- },
- [from.invalid, from.value, onApplyFromProps, timeZone, to.invalid, to.value, fiscalYearStartMonth]
- );
+ onApplyFromProps(timeRange);
+ }, [from.invalid, from.value, onApplyFromProps, timeZone, to.invalid, to.value, fiscalYearStartMonth]);
const onChange = useCallback(
(from: DateTime | string, to: DateTime | string) => {
@@ -92,6 +88,12 @@ export const TimeRangeForm = (props: Props) => {
[timeZone]
);
+ const submitOnEnter = (event: React.KeyboardEvent) => {
+ if (event.key === 'Enter') {
+ onApply();
+ }
+ };
+
const fiscalYear = rangeUtil.convertRawToRange({ from: 'now/fy', to: 'now/fy' }, timeZone, fiscalYearStartMonth);
const fyTooltip = (
@@ -115,13 +117,14 @@ export const TimeRangeForm = (props: Props) => {
);
return (
-