Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Datepicker] Allow selecting dates when from is undefined #3655

Merged
merged 6 commits into from
Mar 13, 2025

Conversation

KenAJoh
Copy link
Collaborator

@KenAJoh KenAJoh commented Mar 12, 2025

Description

Resolves: https://nav-it.slack.com/archives/C7NE7A8UF/p1741793003704079

Component Checklist 📝

  • JSDoc
  • Examples
  • Documentation / Decision Records
  • Storybook
  • Style mappings (@navikt/core/css/config/_mappings.js)
  • Component tokens (@navikt/core/css/tokens.json)
  • CSS class deprecations (@navikt/aksel-stylelint/src/deprecations.ts)
  • Exports (@navikt/core/react/src/index.ts and @navikt/core/react/package.json)
  • New component? CSS import (@navikt/core/css/index.css)
  • Breaking change? Update migration guide. Consider codemod.
  • Changeset (Format: <Component>: <gitmoji?> <Text>. E.g. "Button: ✨ Add feature xyz.")

Sorry, something went wrong.

@KenAJoh KenAJoh requested a review from Copilot March 12, 2025 19:25
Copy link

changeset-bot bot commented Mar 12, 2025

🦋 Changeset detected

Latest commit: 2ab3506

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Choose a reason for hiding this comment

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

Pull Request Overview

This PR addresses an issue in the ranged datepicker where selecting dates with an undefined “from” was problematic. The key changes include an updated onSelect handler in the DatePicker.RDP component, simplified state updates in the useRangeDatepicker hook, and minor adjustments to the stories and changeset documentation.

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.

File Description
@navikt/core/react/src/date/datepicker/parts/DatePicker.RDP.tsx Updates the onSelect callback to handle cases when “from” is undefined in range mode.
.changeset/eleven-flowers-roll.md Documents the fix for selecting new dates when “from” is undefined.
@navikt/core/react/src/date/datepicker/DatePicker.stories.tsx Adjusts the default selection and comment outs the range change and validate callbacks.
@navikt/core/react/src/date/datepicker/hooks/useRangeDatepicker.tsx Simplifies state update logic by removing legacy handling of previous “to” values.
Comments suppressed due to low confidence (2)

@navikt/core/react/src/date/datepicker/parts/DatePicker.RDP.tsx:91

  • Verify that this condition correctly distinguishes between standard selections and the edge case for a range selection with an undefined 'from'. Adding tests for these edge cases might improve confidence in the behavior.
if (mode !== "range" || newSelection || !isDateRange(selected)) {

@navikt/core/react/src/date/datepicker/hooks/useRangeDatepicker.tsx:377

  • The removal of the previous logic for handling the 'to' date (prevToRange and resetTo) simplifies state updates; ensure that this change still accounts for scenarios where only a 'to' value is present or when resetting the range selection.
setFromInputValue( range?.from ? formatDateForInput(range.from, locale, "date", inputFormat) : "", );
Copy link
Contributor

github-actions bot commented Mar 12, 2025

Storybook demo / Chromatic

eb30bf124 | 91 components | 135 stories

KenAJoh and others added 3 commits March 13, 2025 09:28
@KenAJoh KenAJoh merged commit 4eba5a9 into main Mar 13, 2025
6 checks passed
@KenAJoh KenAJoh deleted the datepicker-no-reselect-range branch March 13, 2025 13:48
@github-actions github-actions bot mentioned this pull request Mar 12, 2025
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.

None yet

1 participant