-
Notifications
You must be signed in to change notification settings - Fork 72
[LG-5504] feat(input-box): Add segment focus behavior #3322
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
base: shaneeza/time-picker-integration
Are you sure you want to change the base?
[LG-5504] feat(input-box): Add segment focus behavior #3322
Conversation
… improved type handling and event management
…tSegment with additional props
…with improved type handling and segment management
…ved segment management and type handling
…es for better segment management
…pe 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
…ean up InputBox component
…alidation and formatting functions
…tSegment and InputBox tests for better coverage
…ent components by introducing utility functions
…gment components for improved clarity and documentation
…ent types with clearer examples
…Rules in InputBox types for better clarity
…ting getValueFormatter to accept segment-specific character counts
… for year segment and enhance validation logic
…ype safety and clarity
…ng and props validation
…r consistency and clarity across components
… tests for InputBox and InputSegment components
…/leafygreen-ui into LG-5504/input-box-segment-focus
…db/leafygreen-ui into LG-5504/input-box-segment-focus
…/leafygreen-ui into LG-5504/input-box-in-date-picker-3
…d and mouse interaction specs
…db/leafygreen-ui into LG-5504/input-box-segment-focus
…ed segment handling in DatePickerInput
…lementation in DatePickerInput
…tToFocus utilities
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.
This was moved from DatePicker with git mv but I think renaming the file ended up making this a new file
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 extracts and generalizes segment focus functionality from DatePicker into reusable utilities in the InputBox package. The changes enable other components to implement segment-based input focus behavior without duplicating the logic.
Key Changes:
- Moved
getFirstEmptySegmentandgetSegmentToFocusutilities fromDatePickertoInputBoxwith generic typing - Added
focusAndSelectSegmentconvenience wrapper that combines focus logic with DOM manipulation - Updated
DatePickerto consume the new utilities fromInputBox
Reviewed Changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
packages/input-box/src/utils/index.ts |
Exports new utility functions for segment focus management |
packages/input-box/src/utils/getSegmentToFocus/getSegmentToFocus.ts |
Moved and generalized with optional parameters and improved typing |
packages/input-box/src/utils/getSegmentToFocus/getSegmentToFocus.spec.tsx |
Comprehensive test coverage for segment focus logic |
packages/input-box/src/utils/getFirstEmptySegment/getFirstEmptySegment.ts |
Extracted utility to find first empty segment with generic typing |
packages/input-box/src/utils/getFirstEmptySegment/getFirstEmptySegment.spec.ts |
Test coverage for empty segment detection |
packages/input-box/src/utils/focusAndSelectSegment/focusAndSelectSegment.ts |
New convenience wrapper combining focus and select operations |
packages/input-box/src/utils/focusAndSelectSegment/focusAndSelectSegment.spec.tsx |
Tests for the focus and select wrapper |
packages/input-box/src/index.ts |
Updated exports to include new utilities |
packages/date-picker/src/shared/utils/index.ts |
Removed export of old getFirstEmptySegment |
packages/date-picker/src/shared/utils/getFirstEmptySegment/index.ts |
Deleted file after extraction to InputBox |
packages/date-picker/src/DatePicker/utils/getSegmentToFocus/getSegmentToFocus.spec.ts |
Removed tests now covered in InputBox |
packages/date-picker/src/DatePicker/DatePickerInput/DatePickerInput.tsx |
Updated to use focusAndSelectSegment from InputBox |
|
|
||
| import { getSegmentToFocus, SegmentRefsType } from './getSegmentToFocus'; | ||
|
|
||
| describe('packages/date-picker/utils/getSegmentToFocus', () => { |
Copilot
AI
Nov 20, 2025
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.
The describe block references 'date-picker' but this test is now in the 'input-box' package. Update to 'packages/input-box/utils/getSegmentToFocus'.
| describe('packages/date-picker/utils/getSegmentToFocus', () => { | |
| describe('packages/input-box/utils/getSegmentToFocus', () => { |
…/leafygreen-ui into LG-5504/input-box-segment-focus
stephl3
left a comment
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.
can we add some interaction tests to capture the expected visual focus styles when a particular segment is clicked/focused?
packages/input-box/src/utils/focusAndSelectSegment/focusAndSelectSegment.spec.tsx
Show resolved
Hide resolved
packages/input-box/src/utils/getFirstEmptySegment/getFirstEmptySegment.spec.ts
Show resolved
Hide resolved
packages/input-box/src/utils/getSegmentToFocus/getSegmentToFocus.spec.tsx
Show resolved
Hide resolved
| { type: 'day', value: '' }, | ||
| ]; | ||
|
|
||
| test('focuses and selects the target segment', () => { |
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.
any other cases we want to test beyond the happy path?
…erage and edge case handling
@stephl3 Individual segments don't have focus styles. It's up to the consuming component to add a focus outline to the input container with |
I see some focus styles being set in |
…attribute support in stories and styles
…ng support for data-focus attribute
@stephl3 Ahh you're correct. I had it in my mind that that was a native browser background color. In that case, I've updated the generated story to include focus styles. |
|
Coverage after merging LG-5504/input-box-segment-focus into shaneeza/time-picker-integration will be
Coverage Report
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

✍️ Proposed changes
This PR adds an exportable util that provides segment focus functionality, which was initially missed when extracting logic from
DatePickerintoInputBox. However, this functionality will not be used directly inInputBox.This util should be used in an
onClickcallback in the element wrapping theInputBoxcomponent. This is necessary because the wrapping element will contain the height/padding, and we need that height to be included in the clickable area for proper focus behavior.For example, in
DatePicker, this util is used withinDateInputInput'sonClickhandler, sinceDateInputInputconsumesDateInputBox, which in turn consumesInputBox.🎟 Jira ticket: Name of ticket
✅ Checklist
For bug fixes, new features & breaking changes
pnpm changesetand documented my changes