Skip to content

fix(DatePicker): call onChange for typed dates - #23165

Open
Subhom1 wants to merge 3 commits into
carbon-design-system:mainfrom
Subhom1:fix-date-picker-typed-onchange-23122
Open

fix(DatePicker): call onChange for typed dates#23165
Subhom1 wants to merge 3 commits into
carbon-design-system:mainfrom
Subhom1:fix-date-picker-typed-onchange-23122

Conversation

@Subhom1

@Subhom1 Subhom1 commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

Closes #23122

Fixes DatePicker so typing a complete valid date in a single picker calls onChange immediately, matching the calendar selection path. The typed commit path only runs for valid, fully formatted values and avoids duplicate callbacks when the input later blurs.

Changelog

New

  • Added React DatePicker test coverage for typed valid dates using the default format.
  • Added React DatePicker test coverage for typed valid dates using a custom d.m.Y format.
  • Added React DatePicker test coverage to ensure invalid custom-format typed values are not committed.

Changed

  • Updated single DatePicker input handling to commit complete valid typed values through the flatpickr instance immediately.
  • Avoided duplicate typed commits from flatpickr-generated input events and blur after a typed date is already selected.
  • Updated the existing parseDate test mock so it behaves like a reusable parser across typed and Enter commit paths.

Removed

  • None.

Testing / Reviewing

  1. Run the focused DatePicker tests:

    BABEL_ENV=test ./node_modules/.bin/jest packages/react/src/components/DatePicker/DatePicker-test.js --runInBand --silent
    
  2. Run formatting and whitespace checks:

    yarn prettier --check packages/react/src/components/DatePicker/DatePicker.tsx packages/react/src/components/DatePicker/DatePicker-test.js
    git diff --check
    
  3. In Storybook, open Components/DatePicker/Single with calendar.

  4. Type a complete valid date into the input without pressing Enter or blurring.

  5. Confirm onChange fires immediately in the Actions panel.

  6. Blur the input and confirm onChange is not duplicated for the same typed value.

  7. Type an invalid custom-format date in a DatePicker using dateFormat="d/m/Y" and confirm it is not committed as a selected date while typing.

PR Checklist

As the author of this PR, before marking ready for review, confirm you:

  • Reviewed every line of the diff
  • Updated documentation and storybook examples
  • Followed the
    required v12 migration documentation
    for any code change that affects v12, or struck through this item because
    the PR does not affect v12
  • Wrote passing tests that cover this change
  • Addressed any impact on accessibility (a11y)
  • Tested for cross-browser consistency
  • Validated that this code is ready for review and status checks should pass

@Subhom1
Subhom1 requested a review from a team as a code owner August 28, 2026 20:41
@Subhom1
Subhom1 requested review from annawen1 and heloiselui August 28, 2026 20:41
@netlify

netlify Bot commented Aug 28, 2026

Copy link
Copy Markdown

Deploy Preview for v12-carbon-react ready!

Name Link
🔨 Latest commit a680817
🔍 Latest deploy log https://app.netlify.com/projects/v12-carbon-react/deploys/6a932c9be33f910008069339
😎 Deploy Preview https://deploy-preview-23165--v12-carbon-react.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify

netlify Bot commented Aug 28, 2026

Copy link
Copy Markdown

Deploy Preview for v12-carbon-web-components ready!

Name Link
🔨 Latest commit a680817
🔍 Latest deploy log https://app.netlify.com/projects/v12-carbon-web-components/deploys/6a932c9b4344450008f60535
😎 Deploy Preview https://deploy-preview-23165--v12-carbon-web-components.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify

netlify Bot commented Aug 28, 2026

Copy link
Copy Markdown

Deploy Preview for v11-carbon-react ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit a5a16ed
🔍 Latest deploy log https://app.netlify.com/projects/v11-carbon-react/deploys/6a91f28a9c53a60008c63201
😎 Deploy Preview https://deploy-preview-23165--v11-carbon-react.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify

netlify Bot commented Aug 28, 2026

Copy link
Copy Markdown

Deploy Preview for v11-carbon-web-components ready!

Name Link
🔨 Latest commit a5a16ed
🔍 Latest deploy log https://app.netlify.com/projects/v11-carbon-web-components/deploys/6a91f28a032ea300088cad85
😎 Deploy Preview https://deploy-preview-23165--v11-carbon-web-components.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify

netlify Bot commented Aug 28, 2026

Copy link
Copy Markdown

Deploy Preview for carbon-elements ready!

Name Link
🔨 Latest commit a5a16ed
🔍 Latest deploy log https://app.netlify.com/projects/carbon-elements/deploys/6a91f28a26635e0008777b06
😎 Deploy Preview https://deploy-preview-23165--carbon-elements.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify

netlify Bot commented Aug 28, 2026

Copy link
Copy Markdown

Deploy Preview for v11-carbon-react ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit a680817
🔍 Latest deploy log https://app.netlify.com/projects/v11-carbon-react/deploys/6a932c9b042d0e00081ffedf
😎 Deploy Preview https://deploy-preview-23165--v11-carbon-react.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify

netlify Bot commented Aug 28, 2026

Copy link
Copy Markdown

Deploy Preview for v11-carbon-web-components ready!

Name Link
🔨 Latest commit a680817
🔍 Latest deploy log https://app.netlify.com/projects/v11-carbon-web-components/deploys/6a932c9b1311e10007743513
😎 Deploy Preview https://deploy-preview-23165--v11-carbon-web-components.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify

netlify Bot commented Aug 28, 2026

Copy link
Copy Markdown

Deploy Preview for carbon-elements ready!

Name Link
🔨 Latest commit a680817
🔍 Latest deploy log https://app.netlify.com/projects/carbon-elements/deploys/6a932c9b356ecc00085afbbf
😎 Deploy Preview https://deploy-preview-23165--carbon-elements.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@codecov

codecov Bot commented Aug 28, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.68%. Comparing base (615ebfc) to head (a680817).

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #23165      +/-   ##
==========================================
- Coverage   89.69%   89.68%   -0.01%     
==========================================
  Files         640      640              
  Lines       59141    59171      +30     
  Branches     8305     8356      +51     
==========================================
+ Hits        53047    53070      +23     
- Misses       5927     5934       +7     
  Partials      167      167              
Flag Coverage Δ
main-packages 87.15% <100.00%> (+0.03%) ⬆️
web-components 90.56% <ø> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ 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.

}

const expectedValueLength = calendar.formatDate(
new Date(2000, 10, 22),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you explain this value?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, Good callout. This is just a representative fixed date used to derive the expected length of a complete value for the active dateFormat.

For example:

  • m/d/Y formats new Date(2000, 10, 22) as 11/22/2000
  • d.m.Y formats it as 22.11.2000

So the input handler can skip parsing partial typed values until the user has entered enough characters for that format. I used month/day 22 and year 2000 because they produce two-digit day/month and a four-digit year, avoiding a shorter formatted value like 1/2/2000.

I can add a short comment here to make that intent clearer.

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.

[Bug]: DatePicker: typing a valid date fills the input but does not call onChange

2 participants