Skip to content

Conversation

@shaneeza
Copy link
Collaborator

@shaneeza shaneeza commented Nov 6, 2025

✍️ Proposed changes

This PR is the third PR in a series of three PRs that add the new InputBox package and integrate it into the existing DatePicker package:

  1. [LG-5504] feat(input-box): add InputSegment  #3293
  2. [LG-5504] feat(input-box): add InputBox #3285
  3. This PR

This PR refactors the date-picker package to leverage the new @leafygreen-ui/input-box component instead of maintaining custom input segment implementations. This migration significantly simplifies the codebase by removing redundant logic and utilities, while maintaining the same functionality through the shared input-box component.

Key changes include:

  • Replaced custom DateInputSegment implementation with InputSegment from @leafygreen-ui/input-box
  • Removed custom keyboard navigation, value formatting, and validation logic, now handled by input-box
  • Deleted obsolete utility functions and their tests (1,319 deletions, 146 insertions)
  • Simplified DatePickerInput and DateInputBox components

🎟️ Jira ticket: LG-5504

✅ Checklist

  • I have added stories/tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)
  • I have run pnpm changeset and documented my changes

🧪 How to test changes

  1. Navigate to the date-picker component in Storybook
  2. Test all keyboard navigation (arrow keys, tab, backspace) within date input segments
  3. Verify that date input segments behave identically to the previous implementation
  4. Test edge cases: min/max date constraints, placeholder behavior, and value formatting
  5. Ensure all existing date-picker tests pass

… improved type handling and event management
…with improved type handling and segment management
… new props for step handling and rollover management
…icker components for improved segment management and type handling
…nce segment validation logic for improved date handling
…tSegment and InputBox tests for better coverage
…ent components by introducing utility functions
…gment components for improved clarity and documentation
…ting getValueFormatter to accept segment-specific character counts
… for year segment and enhance validation logic
… tests for InputBox and InputSegment components
@shaneeza shaneeza requested a review from a team as a code owner November 6, 2025 19:25
Comment on lines 39 to 43
ctx?.args.segment === 'day'
? 'DD'
: ctx?.args.segment === 'month'
? 'MM'
: 'YYYY'
Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

turns out i don't even need this, removing

@shaneeza shaneeza changed the title [LG-5504] refactor(date-picker): migrate to use input-box component [LG-5504] refactor(date-picker): migrate to use InputBox component Nov 10, 2025
@shaneeza shaneeza marked this pull request as draft November 12, 2025 14:16
@shaneeza shaneeza marked this pull request as ready for review November 12, 2025 21:51
…reen-ui into LG-5504/input-box-in-date-picker-3
@shaneeza shaneeza requested a review from a team November 13, 2025 16:10
…reen-ui into LG-5504/input-box-in-date-picker-3
const segment = part.type as DateSegment;
const formatter = getValueFormatter(segment);
const formatter = getValueFormatter({
charsPerSegment: charsPerSegment[segment],
Copy link
Collaborator

Choose a reason for hiding this comment

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

It feels like there could be some confusion that the charsPerSegment param is a number while the charsPerSegment const is an object mapping a segment to a number. Could be helpful to rename charsPerSegment constant more explicitly. i.e. charsPerSegmentObj or charsPerSegmentMap

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good call out. I like charsPerSegmentObj

Copy link
Collaborator Author

@shaneeza shaneeza Nov 19, 2025

Choose a reason for hiding this comment

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

Or maybe changing the param to charsCount might be better, so that getValueFormatter is not exclusive to segments if we want to use this somewhere else in the future.

Comment on lines 19 to 23
customValidation:
segment === DateSegment.Year
? (value: DateSegmentValue) => inRange(Number(value), 1000, 9999 + 1)
: undefined,
}),
Copy link
Collaborator

Choose a reason for hiding this comment

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

could we add a comment about what this is for? does this override min / max validation?

Comment on lines 10 to 15
export interface DateInputBoxProviderProps {
/**
* Date value in UTC time
*/
value?: DateType;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think something like this could work as well and be a little DRYer

Suggested change
export interface DateInputBoxProviderProps {
/**
* Date value in UTC time
*/
value?: DateType;
}
export interface DateInputBoxProviderProps extends PropsWithChildren<DateInputBoxContextType> {};

Comment on lines 102 to 113
onKeyDown={onKeyDown}
segmentRefs={segmentRefs}
segmentEnum={DateSegment}
charsPerSegment={charsPerSegment}
formatParts={formatParts}
segments={segments}
setSegment={setSegment}
disabled={disabled}
segmentRules={dateSegmentRules}
onSegmentChange={onSegmentChange}
labelledBy={labelledBy}
segmentComponent={DateInputSegment}
Copy link
Collaborator

Choose a reason for hiding this comment

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

if there are props that are not used for component logic, can we instead pass them through to InputBox through the spread ...rest?

@shaneeza shaneeza marked this pull request as draft November 17, 2025 14:33
…ygreen-ui into LG-5504/input-box-in-date-picker-3
…elated references to charsCount for consistency
…ate DateInputBoxProviderProps to extend PropsWithChildren for better type handling
…-digit year value in custom validation for date segments
…tead of charsPerSegment across components and tests for consistency
@shaneeza shaneeza marked this pull request as ready for review November 19, 2025 15:55
@shaneeza shaneeza requested a review from stephl3 November 19, 2025 15:55
@github-actions
Copy link
Contributor

Coverage after merging LG-5504/input-box-in-date-picker-3 into LG-5504/input-box-component will be

78.87%

Coverage Report
FileStmtsBranchesFuncsLinesUncovered Lines
charts/chart-card/src/ChartCard
   ChartCardContext.tsx60%100%50%66.67%25
charts/colors/src
   colors.ts0%100%100%0%25, 44, 5
charts/core/src
   constants.ts50%100%0%66.67%13
charts/core/src/Axis
   Axis.ts0%0%0%0%15, 19, 21, 23, 23, 45, 45, 61
   XAxis.tsx0%0%0%0%15, 19, 31, 34, 34, 58–60, 62–63, 63, 63, 65, 67, 71, 78
   YAxis.tsx0%0%0%0%15, 19, 30, 33, 33, 57–59, 61–62, 62, 62, 64, 66, 70, 77
charts/core/src/Chart
   Chart.tsx81.25%66.67%100%100%58, 64, 95
charts/core/src/Chart/config
   getDefaultChartOptions.ts100%100%100%100%
charts/core/src/Chart/hooks
   useChart.ts77.01%82.14%76.92%73.91%118, 118, 118–119, 123, 123, 123–125, 128, 132, 136–137, 139–140, 92, 98
   useTooltipVisibility.ts41.56%25%40%49.44%109–110, 120, 131, 133, 133, 133, 133, 133–135, 145, 145, 145–146, 149, 149, 149–151, 153–154, 166, 166, 166–167, 170, 170, 170–171, 171, 174–176, 190, 190, 190–191, 194, 194, 194–195, 195, 198–199, 224, 224, 228–229, 231–234, 276, 280–283, 46, 55, 55, 55, 55, 55–56, 59–60, 78, 78, 78–79, 87, 91–93
charts/core/src/ChartContext
   ChartContext.tsx83.33%50%100%87.50%21–22
charts/core/src/ChartHeader
   ChartHeader.tsx100%100%100%100%
charts/core/src/ChartTooltip
   ChartTooltip.tsx0%0%0%0%100–101, 105–106, 106, 106, 108, 111, 111, 115, 115, 115, 143, 143, 147–148, 163, 22, 35–36, 38, 40, 64, 70–71, 71, 71, 77, 82–83, 87, 87, 87–88, 92, 97–98
   utils.ts100%100%100%100%
charts/core/src/ChartTooltip/CustomTooltip
   CustomTooltip.testUtils.ts0%100%100%0%3
   CustomTooltip.tsx78.26%66.67%100%88.89%46–47, 54, 60, 69
charts/core/src/ChartTooltip/CustomTooltip/SeriesList
   SeriesList.tsx90.91%83.33%100%91.67%15, 19
charts/core/src/ChartTooltip/CustomTooltip/SeriesListItem
   SeriesListItem.tsx90%87.50%100%90.91%27–28
charts/core/src/ChartTooltip/CustomTooltip/SeriesListItemColorDot
   SeriesListItemColorDot.tsx100%100%100%100%
charts/core/src/Echart
   initializeEcharts.ts85.19%75%100%85.71%30–31, 73–74
   updateUtils.tsx0%0%0%0%10, 12, 12, 12–13, 17, 24, 26, 26, 26–28, 32, 46, 48–49, 49, 49–50, 50, 54, 57, 61, 68, 7, 9, 9, 9
   useEchart.ts53.51%41.11%67.86%58.17%109–110, 117, 124, 124, 124, 126, 126, 126, 126, 126–127, 130, 138, 140, 140, 140–141, 144, 153, 155, 155, 155–156, 160, 160, 160–161, 161, 161, 163, 174–175, 184–185, 188, 190, 192–193, 197, 210–211, 218–219, 222, 224–225, 227, 227, 227, 229, 229, 229–230, 230, 230–231, 235–236, 236, 236, 238–239, 239, 239–240, 245, 251, 256–258, 263, 271, 273, 273, 273–274, 277, 285, 287, 287, 287–288, 291, 297, 299, 299, 299–300, 303, 317, 320, 324, 324–325, 334, 347–350, 350, 357–358, 358, 365–367, 385–386, 423–424, 45–46, 59–60, 73–74
charts/core/src/Echart/utils
   updateUtils.ts97.06%90%100%100%26
charts/core/src/EventMarkers/BaseEventMarker
   BaseEventMarker.tsx0%0%0%0%18, 23–24, 27, 27, 27, 31–32, 32, 32, 40, 44–45, 60
   utils.ts0%0%0%0%102, 102, 115, 16, 33–34, 46, 51, 51, 55, 55, 60, 60, 74, 80, 80, 80–81
charts/core/src/EventMarkers/EventMarkerLine
   EventMarkerLine.tsx0%0%0%0%11, 13
charts/core/src/EventMarkers/EventMarkerPoint
   EventMarkerPoint.tsx0%0%0%0%11, 13
charts/core/src/Series
   Series.tsx0%0%0%0%23–26, 26, 26–27, 29–30, 30, 30, 32, 32, 32–34, 41, 44, 49, 63, 66
charts/core/src/Series/Bar
   Bar.tsx0%0%0%0%18, 18, 18, 18, 20, 22, 24, 42, 46, 48, 51, 64, 67, 9
charts/core/src/Series/Line
   Line.tsx0%100%0%0%12, 35–36, 44
charts/core/src/ThresholdLine
   ThresholdLine.tsx0%0%0%0%101, 103–104, 104, 104, 112, 114–115, 119, 30, 60, 60, 98–99
charts/core/src/testUtils
   makeSeriesData.testUtils.ts0%0%0%0%10, 106–107, 109, 111, 114–115, 117–118, 125, 127, 127, 138, 142–143, 146, 149, 15, 151–152, 16, 167, 17, 170–172, 175–176, 182, 185, 187–188, 192, 20,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants