Skip to content

fix: honor calendarStartDay when navigating with the End key - #6327

Open
balajis-qb wants to merge 1 commit into
Hacker0x01:mainfrom
qburst:fix/6326-end-key-calendar-start-day
Open

balajis-qb wants to merge 1 commit into
Hacker0x01:mainfrom
qburst:fix/6326-end-key-calendar-start-day

Conversation

@balajis-qb

Copy link
Copy Markdown
Contributor

Summary

Fixes #6326.

Problem

The calendar lets you jump to the first day of the week with the Home key and to the last day of the week with the End key. When weeks are configured to start on a day other than Sunday (for example calendarStartDay={1} for a Monday–Sunday week), Home respected that setting but End did not.

The cause: the Home handler passed locale and calendarStartDay to getStartOfWeek, but the End handler called getEndOfWeek(date) with no configuration, so date-fns fell back to its own default of a Sunday–Saturday week.

Example — with calendarStartDay={1}, focus on Wednesday, June 12, 2024:

Key Before After
Home Mon, Jun 10 ✅ Mon, Jun 10 ✅
End Sat, Jun 15 ❌ Sun, Jun 16 ✅

The keyboard handler before the fix:

case KeyType.Home:
  newCalculatedDate = getStartOfWeek(date, locale, calendarStartDay);
  break;
case KeyType.End:
  newCalculatedDate = getEndOfWeek(date); // locale + calendarStartDay dropped
  break;

Changes

  • src/date_utils.ts: getEndOfWeek now accepts optional locale and calendarStartDay arguments, mirroring getStartOfWeek, and forwards them to date-fns endOfWeek via { locale, weekStartsOn }.
  • src/index.tsx: the End case in the keyboard handler now calls getEndOfWeek(date, locale, calendarStartDay), so Home and End compute symmetric week boundaries.
  • src/test/date_utils_test.test.ts: new getEndOfWeek tests — default Sunday–Saturday week, Monday–Sunday week via calendarStartDay, and symmetry with getStartOfWeek.
  • src/test/datepicker_test.test.tsx: new test asserting End moves focus to Sunday, June 16, 2024 with calendarStartDay={1}.

The new parameters are optional, so existing single-argument callers and tests are unaffected. yarn test:ci (43 suites, 1489 tests), yarn type-check, and yarn eslint all pass.

react date picker

Contribution checklist

  • I have followed the contributing guidelines.
  • I have added sufficient test coverage for my changes.
  • I have formatted my code with Prettier and checked for linting issues with ESLint for code readability.

@codecov

codecov Bot commented Sep 8, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.32%. Comparing base (548a1f3) to head (9c4bba5).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6327      +/-   ##
==========================================
+ Coverage   99.29%   99.32%   +0.02%     
==========================================
  Files          30       30              
  Lines        3822     3826       +4     
  Branches     1648     1651       +3     
==========================================
+ Hits         3795     3800       +5     
+ Misses         26       25       -1     
  Partials        1        1              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

The Home keyboard handler passed `locale` and `calendarStartDay` to
`getStartOfWeek`, but the End handler called `getEndOfWeek(date)` with no
configuration. With a non-Sunday week start (e.g. `calendarStartDay={1}`),
End moved focus to Saturday instead of the configured last day (Sunday).

`getEndOfWeek` now accepts optional `locale` and `calendarStartDay`
arguments, mirroring `getStartOfWeek`, and the End handler forwards both so
Home and End compute symmetric week boundaries.

Fixes Hacker0x01#6326
@balajis-qb
balajis-qb force-pushed the fix/6326-end-key-calendar-start-day branch from be5f7ea to 9c4bba5 Compare September 8, 2026 10:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

End key ignores calendarStartDay for non-Sunday weeks

1 participant