Skip to content

fix: snap initial preSelection to first enabled day in month#6288

Closed
GauravDhuri wants to merge 1 commit into
Hacker0x01:mainfrom
GauravDhuri:fix-opentodate-disabled-day-preselection-6286
Closed

fix: snap initial preSelection to first enabled day in month#6288
GauravDhuri wants to merge 1 commit into
Hacker0x01:mainfrom
GauravDhuri:fix-opentodate-disabled-day-preselection-6286

Conversation

@GauravDhuri

@GauravDhuri GauravDhuri commented Jun 12, 2026

Copy link
Copy Markdown

name: Pull Request
about: Create a pull request to improve this repository
title: ""
labels: ""
assignees: ""

Description

Linked issue: #6286

Problem
When openToDate (or the bounded default preselection) falls on a day that isn't selectable. For example gap between includeDates, or a day removed by excludeDates/filterDate.. the calendar opens with no focusable day. The roving tabindex="0" is only applied to the pre-selected day when that day is enabled (Day.isKeyboardSelected), so when the preselection is disabled, no day in the grid is reachable. Keyboard and screen-reader users cannot move into the calendar at all.

Month navigation already guarded against this via Calendar.getEnabledPreSelectionDateForMonth, but the initial open path in calcInitialState did not, so the bug appared whenever the calendar first opened onto a disabled day.

Changes

  • Added a shared getEnabledDateInMonth (date, options) util in date_utils.ts: returns the date if its enabled, otherwise the first enabled day in that month or null if the month has none.
  • calcInitialState now snaps the bounded preselection through this util, keeping the initial open and month navigation paths consistent
  • Added tests: unit coverage for getEnabledDateInMonth and integration coverage asserting a focusable day exists when openToDate lands on a gap.

Screenshots

To reviewers

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.

When openToDate (or the bounded default) lands on a disabled day - such as a gap between includedDates - preSelection became a disabled date, leaving no day with tabindex="0" in the grid. This breaks keyboard and screen-reader navigation, as there is no focusable day to enter the calendar.

calcInitialState now snaps the bounded preSelection to the first enabled day in its month, reusing a new shared getEnabledDateInMonth util. The same logic already backed month navigation (Calendar.getEnabledPreSelectionDateForMonth), which is refactored to use the shared util so both paths stay consistent.

Fixes Hacker0x01#6286
@GauravDhuri GauravDhuri force-pushed the fix-opentodate-disabled-day-preselection-6286 branch from d6e3212 to eeb47d8 Compare June 13, 2026 13:57
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.

1 participant