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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ All notable changes to this project will be documented in this file.
- Fixed issue with timestamps being rendered incorrectly in segment menus and modals for some timezones
- Fixed main graph being clipped when the browser's root font size is smaller than the default 16px
- Fixed issue with users with billing role not being able to create personal segments
- Fixed period arrow keys hijacking custom-range calendar

## v3.2.0 - 2026-01-16

Expand Down
6 changes: 4 additions & 2 deletions assets/js/dashboard/keybinding.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,13 @@ export function Keybind(opts: KeybindOptions) {
export function NavigateKeybind({
keyboardKey,
type,
navigateProps
navigateProps,
shouldAlsoIgnoreWhen = []
}: {
keyboardKey: string
type: KeyboardEventType
navigateProps: AppNavigationTarget
shouldAlsoIgnoreWhen?: Array<(event: KeyboardEvent) => boolean>
}) {
const navigate = useAppNavigate()
const handler = useCallback(() => {
Expand All @@ -129,7 +131,7 @@ export function NavigateKeybind({
keyboardKey={keyboardKey}
type={type}
handler={handler}
shouldIgnoreWhen={[isModifierPressed, isTyping]}
shouldIgnoreWhen={[isModifierPressed, isTyping, ...shouldAlsoIgnoreWhen]}
targetRef="document"
/>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,36 @@ test.each([
}
)

test('arrow keys shift the period when the custom-range calendar is closed, but not while it is open', async () => {
const localDomain = 'no-arrow-hijack.test'
const startUrl = `${getRouterBasepath({ domain: localDomain, shared: false })}${stringifySearch({ period: 'month', date: '2024-08-15' })}`

render(<DashboardPeriodPicker />, {
wrapper: (props) => (
<TestContextProviders
siteOptions={{ domain: localDomain, statsBegin: '2020-01-01' }}
routerProps={{ initialEntries: [startUrl] }}
{...props}
/>
)
})

expect(screen.getByText('August 2024')).toBeVisible()
expect(document.querySelector('.flatpickr-calendar')).toBeNull()

await userEvent.keyboard('{ArrowLeft}')
expect(screen.getByText('July 2024')).toBeVisible()

await userEvent.keyboard('c')
expect(document.querySelector('.flatpickr-calendar')).not.toBeNull()

await userEvent.keyboard('{ArrowLeft}')
await userEvent.keyboard('{ArrowLeft}')

expect(screen.getByText('July 2024')).toBeVisible()
expect(document.querySelector('.flatpickr-calendar')).not.toBeNull()
})

test('going back resets the stored dashboardState period to previous value', async () => {
const BrowserBackButton = () => {
const navigate = useNavigate()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import React, { useLayoutEffect, useRef } from 'react'
import DatePicker from 'react-flatpickr'
import { CustomLocale } from 'flatpickr/dist/types/locale'

export const isDateRangeCalendarOpen = (): boolean =>
!!document.querySelector('.flatpickr-calendar')

const calendarLocale: Partial<CustomLocale> = {
weekdays: {
shorthand: ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { AppNavigationLink } from '../../navigation/use-app-navigate'
import { DashboardPeriod } from '../../dashboard-time-periods'
import { useMatch } from 'react-router-dom'
import { rootRoute } from '../../router'
import { isDateRangeCalendarOpen } from './date-range-calendar'

const ArrowKeybind = ({
keyboardKey
Expand All @@ -36,6 +37,8 @@ const ArrowKeybind = ({
type="keydown"
keyboardKey={keyboardKey}
navigateProps={{ search }}
// Don't hijack arrow keys flatpickr uses for its own day-cell navigation.
shouldAlsoIgnoreWhen={[isDateRangeCalendarOpen]}
/>
)
}
Expand Down
Loading