From 45faefa8b388400fee63cf83fe739bb0527ac05d Mon Sep 17 00:00:00 2001 From: Joao Silva <100691367+JoaoSilvaGrafana@users.noreply.github.com> Date: Mon, 27 May 2024 10:33:53 +0100 Subject: [PATCH] TimeRangePicker: Allow users to navigate quick ranges with arrows instead of Tab (#88138) --- .../TimeRangePicker/TimeRangeList.tsx | 11 +- .../TimeRangePicker/TimeRangeOption.tsx | 2 + .../TimeRangePicker/hooks.test.tsx | 118 ++++++++++++++++++ .../DateTimePickers/TimeRangePicker/hooks.ts | 75 +++++++++++ 4 files changed, 205 insertions(+), 1 deletion(-) create mode 100644 packages/grafana-ui/src/components/DateTimePickers/TimeRangePicker/hooks.test.tsx create mode 100644 packages/grafana-ui/src/components/DateTimePickers/TimeRangePicker/hooks.ts diff --git a/packages/grafana-ui/src/components/DateTimePickers/TimeRangePicker/TimeRangeList.tsx b/packages/grafana-ui/src/components/DateTimePickers/TimeRangePicker/TimeRangeList.tsx index 0833e099046..76676a5bba6 100644 --- a/packages/grafana-ui/src/components/DateTimePickers/TimeRangePicker/TimeRangeList.tsx +++ b/packages/grafana-ui/src/components/DateTimePickers/TimeRangePicker/TimeRangeList.tsx @@ -8,6 +8,7 @@ import { t } from '../../../utils/i18n'; import { TimePickerTitle } from './TimePickerTitle'; import { TimeRangeOption } from './TimeRangeOption'; +import { useListFocus } from './hooks'; interface Props { title?: string; @@ -44,9 +45,17 @@ export const TimeRangeList = (props: Props) => { const Options = ({ options, value, onChange, title }: Props) => { const styles = useStyles2(getOptionsStyles); + const localRef = React.useRef(null); + const [handleKeys] = useListFocus({ localRef, options }); + return ( <> -