Skip to content

Fix #6298: 🐛 Allow Enter key selection when selected is null#83

Open
balajis-qb wants to merge 1 commit into
mainfrom
issue-6298/fix/year-picker-enter-null-selection
Open

Fix #6298: 🐛 Allow Enter key selection when selected is null#83
balajis-qb wants to merge 1 commit into
mainfrom
issue-6298/fix/year-picker-enter-null-selection

Conversation

@balajis-qb

Copy link
Copy Markdown
Collaborator

Description

Linked issue: Hacker0x01#6298


Problem

In YearPicker (showYearPicker), pressing Enter does not select a year when selected is null or undefined.

This is caused by an early return in onYearKeyDown (src/year.tsx):

if (this.props.selected == null) {
  break;
}

This prevents keyboard-based selection entirely when no initial value is set.

The behavior is inconsistent with:

  • Mouse selection (works correctly)
  • Default DatePicker and MonthPicker (keyboard works even with null selection)

Changes

  • Removed the selected == null guard from Enter key handling
  • Enabled selection based on the currently focused/preselected year
  • Updated test cases to reflect expected behavior
  • Removed/adjusted test enforcing no selection when selected is null

Behavior Changes

  • ✅ Enter key now selects a year even when selected is initially null
  • ✅ Keyboard and mouse interactions are now consistent
  • ✅ Behavior aligned with other picker modes
  • ⚠️ Existing tests expecting no selection on null selected are updated

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.

YearPicker prevented selection via Enter key when `selected` was null
due to an early return in `onYearKeyDown`.

This caused inconsistent behavior compared to:
- Mouse selection (which worked)
- Other picker modes (day/month)

Removed the unnecessary guard and allowed selection based on the
currently focused/preselected year.

Also updated tests that incorrectly enforced the previous behavior.

Closes Hacker0x01#6298
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