@@ -55,7 +55,6 @@ export const TimePicker: React.FC<TimePickerProps> = ({
55
55
const timeValue = parseTimeString ( value , format ) ;
56
56
57
57
const [ showDropdown , setShowDropdown ] = useState ( false ) ;
58
- const [ _focusedSegment , setFocusedSegment ] = useState < number | null > ( null ) ;
59
58
60
59
// Dropdown keyboard navigation state
61
60
const [ dropdownFocus , setDropdownFocus ] = useState < DropdownFocusState > ( {
@@ -89,7 +88,6 @@ export const TimePicker: React.FC<TimePickerProps> = ({
89
88
maxTime,
90
89
} ;
91
90
92
- // Segment labels and placeholders
93
91
const segmentLabels = {
94
92
hours : labels . hours || 'Hours' ,
95
93
minutes : labels . minutes || 'Minutes' ,
@@ -105,7 +103,6 @@ export const TimePicker: React.FC<TimePickerProps> = ({
105
103
} ;
106
104
107
105
const scrollToSelectedOptions = ( ) => {
108
- // Use requestAnimationFrame to ensure DOM is ready
109
106
requestAnimationFrame ( ( ) => {
110
107
const scrollToSelected = ( container : HTMLDivElement | null ) => {
111
108
if ( ! container ) {
@@ -156,7 +153,6 @@ export const TimePicker: React.FC<TimePickerProps> = ({
156
153
}
157
154
158
155
segmentRefs . current [ nextIndex ] ?. focus ( ) ;
159
- setFocusedSegment ( nextIndex ) ;
160
156
} ;
161
157
162
158
const closeDropdown = ( ) => {
@@ -438,8 +434,6 @@ export const TimePicker: React.FC<TimePickerProps> = ({
438
434
format = { format }
439
435
onValueChange = { ( newValue ) => handleSegmentChange ( segmentType , newValue ) }
440
436
onNavigate = { ( direction ) => handleSegmentNavigate ( direction , index ) }
441
- onFocus = { ( ) => setFocusedSegment ( index ) }
442
- onBlur = { ( ) => setFocusedSegment ( null ) }
443
437
placeholder = { segmentPlaceholders [ segmentType ] }
444
438
disabled = { disabled }
445
439
readOnly = { readOnly }
@@ -462,7 +456,9 @@ export const TimePicker: React.FC<TimePickerProps> = ({
462
456
aria-controls = { `${ id } -dropdown` }
463
457
disabled = { disabled || readOnly }
464
458
data-size = 'sm'
465
- onClick = { ( ) => setShowDropdown ( ! showDropdown ) }
459
+ onClick = { ( ) => {
460
+ setShowDropdown ( ! showDropdown ) ;
461
+ } }
466
462
>
467
463
< ClockIcon />
468
464
</ Popover . Trigger >
@@ -497,7 +493,6 @@ export const TimePicker: React.FC<TimePickerProps> = ({
497
493
} }
498
494
onClose = { ( ) => {
499
495
closeDropdown ( ) ;
500
- triggerButtonRef . current ?. focus ( { preventScroll : true } ) ;
501
496
} }
502
497
onKeyDown = { handleDropdownKeyDown }
503
498
tabIndex = { 0 }
@@ -545,7 +540,17 @@ export const TimePicker: React.FC<TimePickerProps> = ({
545
540
} ${ isFocused ? styles . dropdownOptionFocused : '' } ${
546
541
isDisabled ? styles . dropdownOptionDisabled : ''
547
542
} `}
548
- onClick = { ( ) => ! isDisabled && handleDropdownHoursChange ( option . value . toString ( ) ) }
543
+ onClick = { ( ) => {
544
+ if ( ! isDisabled ) {
545
+ handleDropdownHoursChange ( option . value . toString ( ) ) ;
546
+ // Update focus to the clicked option
547
+ setDropdownFocus ( {
548
+ column : 0 ,
549
+ option : optionIndex ,
550
+ isActive : true ,
551
+ } ) ;
552
+ }
553
+ } }
549
554
disabled = { isDisabled }
550
555
aria-label = { option . label }
551
556
>
@@ -590,7 +595,17 @@ export const TimePicker: React.FC<TimePickerProps> = ({
590
595
} ${ isFocused ? styles . dropdownOptionFocused : '' } ${
591
596
isDisabled ? styles . dropdownOptionDisabled : ''
592
597
} `}
593
- onClick = { ( ) => ! isDisabled && handleDropdownMinutesChange ( option . value . toString ( ) ) }
598
+ onClick = { ( ) => {
599
+ if ( ! isDisabled ) {
600
+ handleDropdownMinutesChange ( option . value . toString ( ) ) ;
601
+ // Update focus to the clicked option
602
+ setDropdownFocus ( {
603
+ column : 1 ,
604
+ option : optionIndex ,
605
+ isActive : true ,
606
+ } ) ;
607
+ }
608
+ } }
594
609
disabled = { isDisabled }
595
610
aria-label = { option . label }
596
611
>
@@ -636,7 +651,17 @@ export const TimePicker: React.FC<TimePickerProps> = ({
636
651
} ${ isFocused ? styles . dropdownOptionFocused : '' } ${
637
652
isDisabled ? styles . dropdownOptionDisabled : ''
638
653
} `}
639
- onClick = { ( ) => ! isDisabled && handleDropdownSecondsChange ( option . value . toString ( ) ) }
654
+ onClick = { ( ) => {
655
+ if ( ! isDisabled ) {
656
+ handleDropdownSecondsChange ( option . value . toString ( ) ) ;
657
+ // Update focus to the clicked option
658
+ setDropdownFocus ( {
659
+ column : 2 ,
660
+ option : optionIndex ,
661
+ isActive : true ,
662
+ } ) ;
663
+ }
664
+ } }
640
665
disabled = { isDisabled }
641
666
aria-label = { option . label }
642
667
>
@@ -679,7 +704,14 @@ export const TimePicker: React.FC<TimePickerProps> = ({
679
704
className = { `${ styles . dropdownOption } ${
680
705
isSelected ? styles . dropdownOptionSelected : ''
681
706
} ${ isFocused ? styles . dropdownOptionFocused : '' } `}
682
- onClick = { ( ) => handleDropdownPeriodChange ( period as 'AM' | 'PM' ) }
707
+ onClick = { ( ) => {
708
+ handleDropdownPeriodChange ( period as 'AM' | 'PM' ) ;
709
+ setDropdownFocus ( {
710
+ column : columnIndex ,
711
+ option : optionIndex ,
712
+ isActive : true ,
713
+ } ) ;
714
+ } }
683
715
aria-label = { period }
684
716
>
685
717
{ period }
0 commit comments