-
Notifications
You must be signed in to change notification settings - Fork 42
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
Conversation
🦋 Changeset detectedLatest 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 |
There was a problem hiding this comment.
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) : "", );
Storybook demo / Chromaticeb30bf124 | 91 components | 135 stories |
Description
Resolves: https://nav-it.slack.com/archives/C7NE7A8UF/p1741793003704079
Component Checklist 📝
@navikt/core/css/config/_mappings.js
)@navikt/core/css/tokens.json
)@navikt/aksel-stylelint/src/deprecations.ts
)@navikt/core/react/src/index.ts
and@navikt/core/react/package.json
)@navikt/core/css/index.css
)<Component>: <gitmoji?> <Text>.
E.g. "Button: ✨ Add feature xyz.")