@@ -32,7 +32,18 @@ function convertToLegacyProps(props: TimelinePropsV2): TimelineProps {
32
32
activeItemIndex : props . activeItemIndex ,
33
33
allowDynamicUpdate : props . allowDynamicUpdate ,
34
34
uniqueId : props . id ,
35
- onItemSelected : props . onItemSelected ,
35
+ onItemSelected : props . onItemSelected ?
36
+ ( data : any ) => {
37
+ // Convert from legacy flat structure to new nested structure
38
+ if ( 'item' in data ) {
39
+ // Already in new format
40
+ props . onItemSelected ! ( data ) ;
41
+ } else {
42
+ // Convert from legacy format
43
+ const { index, ...item } = data ;
44
+ props . onItemSelected ! ( { item, index } ) ;
45
+ }
46
+ } : undefined ,
36
47
onScrollEnd : props . onScrollEnd ,
37
48
onThemeChange : props . onThemeChange as any ,
38
49
onRestartSlideshow : props . onRestartSlideshow ,
@@ -402,7 +413,9 @@ const Chrono: React.FunctionComponent<ChronoProps> = (
402
413
// This prevents unwanted resets during dynamic loading and circular updates
403
414
if ( activeItemIndex !== previousActiveItemIndexRef . current ) {
404
415
previousActiveItemIndexRef . current = activeItemIndex ;
405
- handleTimelineUpdate ( activeItemIndex ) ;
416
+ if ( activeItemIndex !== undefined ) {
417
+ handleTimelineUpdate ( activeItemIndex ) ;
418
+ }
406
419
}
407
420
} , [ activeItemIndex , handleTimelineUpdate ] ) ;
408
421
@@ -427,15 +440,15 @@ const Chrono: React.FunctionComponent<ChronoProps> = (
427
440
if ( ! timeLineItems . length ) {
428
441
return ;
429
442
}
430
- if ( activeTimelineItem < timeLineItems . length - 1 ) {
443
+ if ( activeTimelineItem !== undefined && activeTimelineItem < timeLineItems . length - 1 ) {
431
444
const newTimeLineItem = activeTimelineItem + 1 ;
432
445
433
446
// Update timeline state and trigger smooth navigation
434
447
handleTimelineUpdate ( newTimeLineItem ) ;
435
448
setActiveTimelineItem ( newTimeLineItem ) ;
436
449
437
450
if (
438
- mode === 'HORIZONTAL' &&
451
+ mapNewModeToLegacy ( mode ) === 'HORIZONTAL' &&
439
452
slideShowActive &&
440
453
items &&
441
454
items . length - 1 === newTimeLineItem
@@ -453,7 +466,7 @@ const Chrono: React.FunctionComponent<ChronoProps> = (
453
466
] ) ;
454
467
455
468
const handleOnPrevious = useCallback ( ( ) => {
456
- if ( activeTimelineItem > 0 ) {
469
+ if ( activeTimelineItem !== undefined && activeTimelineItem > 0 ) {
457
470
const newTimeLineItem = activeTimelineItem - 1 ;
458
471
459
472
// Update timeline state and trigger smooth navigation
@@ -537,7 +550,7 @@ const Chrono: React.FunctionComponent<ChronoProps> = (
537
550
id = "testette"
538
551
>
539
552
< Timeline
540
- activeTimelineItem = { activeTimelineItem }
553
+ activeTimelineItem = { activeTimelineItem ?? 0 }
541
554
contentDetailsChildren = { contentDetailsChildren }
542
555
iconChildren = { iconChildren }
543
556
items = { timeLineItems }
@@ -553,7 +566,7 @@ const Chrono: React.FunctionComponent<ChronoProps> = (
553
566
slideItemDuration = { slideItemDuration }
554
567
{ ...pickDefined ( {
555
568
onScrollEnd,
556
- onItemSelected,
569
+ onItemSelected : legacyProps . onItemSelected ,
557
570
} ) }
558
571
onOutlineSelection = { handleOutlineSelection }
559
572
mode = { mapNewModeToLegacy ( mode ) }
0 commit comments