@@ -224,6 +224,7 @@ const ObjectPage = forwardRef<HTMLDivElement, ObjectPagePropTypes>((props, ref)
224
224
const [ sectionSpacer , setSectionSpacer ] = useState ( 0 ) ;
225
225
const [ currentTabModeSection , setCurrentTabModeSection ] = useState ( null ) ;
226
226
const sections = mode === ObjectPageMode . IconTabBar ? currentTabModeSection : children ;
227
+ const isScrolling = useRef < ReturnType < typeof setTimeout > | null > ( null ) ;
227
228
228
229
const deprecationNoticeDisplayed = useRef ( false ) ;
229
230
useEffect ( ( ) => {
@@ -336,7 +337,6 @@ const ObjectPage = forwardRef<HTMLDivElement, ObjectPagePropTypes>((props, ref)
336
337
} else {
337
338
scrollToSectionById ( sectionId ) ;
338
339
}
339
- isProgrammaticallyScrolled . current = false ;
340
340
} ;
341
341
342
342
const programmaticallySetSection = ( ) => {
@@ -388,6 +388,7 @@ const ObjectPage = forwardRef<HTMLDivElement, ObjectPagePropTypes>((props, ref)
388
388
}
389
389
return newSelectionSectionId ;
390
390
} ) ;
391
+ prevSelectedSectionId . current = newSelectionSectionId ;
391
392
scrollEvent . current = targetEvent ;
392
393
fireOnSelectedChangedEvent ( targetEvent , index , newSelectionSectionId , section ) ;
393
394
} ;
@@ -448,6 +449,7 @@ const ObjectPage = forwardRef<HTMLDivElement, ObjectPagePropTypes>((props, ref)
448
449
} ) ;
449
450
if ( sectionId ) {
450
451
setInternalSelectedSectionId ( sectionId ) ;
452
+ prevSelectedSectionId . current = sectionId ;
451
453
}
452
454
}
453
455
}
@@ -504,6 +506,7 @@ const ObjectPage = forwardRef<HTMLDivElement, ObjectPagePropTypes>((props, ref)
504
506
if ( mode === ObjectPageMode . IconTabBar ) {
505
507
const sectionId = e . detail . sectionId ;
506
508
setInternalSelectedSectionId ( sectionId ) ;
509
+ prevSelectedSectionId . current = sectionId ;
507
510
const sectionNodes = objectPageRef . current ?. querySelectorAll (
508
511
'section[data-component-name="ObjectPageSection"]'
509
512
) ;
@@ -552,11 +555,11 @@ const ObjectPage = forwardRef<HTMLDivElement, ObjectPagePropTypes>((props, ref)
552
555
}
553
556
return visibleSectionIds . current . has ( section . id ) ;
554
557
} ) ;
555
-
556
- if ( sortedVisibleSections . length > 0 ) {
558
+ if ( sortedVisibleSections . length > 0 && ! isProgrammaticallyScrolled . current ) {
557
559
const section = sortedVisibleSections [ 0 ] ;
558
560
const id = sortedVisibleSections [ 0 ] . id . slice ( 18 ) ;
559
561
setInternalSelectedSectionId ( id ) ;
562
+ prevSelectedSectionId . current = id ;
560
563
debouncedOnSectionChange ( scrollEvent . current , currentIndex , id , section ) ;
561
564
}
562
565
} ) ;
@@ -707,40 +710,46 @@ const ObjectPage = forwardRef<HTMLDivElement, ObjectPagePropTypes>((props, ref)
707
710
} ;
708
711
709
712
const prevScrollTop = useRef ( ) ;
710
- const onObjectPageScroll = useCallback (
711
- ( e ) => {
712
- if ( ! isToggledRef . current ) {
713
- isToggledRef . current = true ;
714
- }
715
- if ( scrollTimeout . current >= performance . now ( ) ) {
713
+ const onObjectPageScroll = ( e ) => {
714
+ if ( ! isToggledRef . current ) {
715
+ isToggledRef . current = true ;
716
+ }
717
+ if ( isScrolling . current ) {
718
+ clearTimeout ( isScrolling . current ) ;
719
+ }
720
+
721
+ isScrolling . current = setTimeout ( ( ) => {
722
+ console . log ( 'end scroll' ) ;
723
+ isProgrammaticallyScrolled . current = false ;
724
+ } , 300 ) ;
725
+
726
+ if ( scrollTimeout . current >= performance . now ( ) ) {
727
+ return ;
728
+ }
729
+ scrollEvent . current = e ;
730
+ if ( typeof props . onScroll === 'function' ) {
731
+ props . onScroll ( e ) ;
732
+ }
733
+ if ( selectedSubSectionId ) {
734
+ setSelectedSubSectionId ( undefined ) ;
735
+ }
736
+ if ( selectionScrollTimeout . current ) {
737
+ clearTimeout ( selectionScrollTimeout . current ) ;
738
+ }
739
+ if ( ! headerPinned || e . target . scrollTop === 0 ) {
740
+ objectPageRef . current ?. classList . remove ( classNames . headerCollapsed ) ;
741
+ }
742
+ if ( scrolledHeaderExpanded && e . target . scrollTop !== prevScrollTop . current ) {
743
+ if ( e . target . scrollHeight - e . target . scrollTop === e . target . clientHeight ) {
716
744
return ;
717
745
}
718
- scrollEvent . current = e ;
719
- if ( typeof props . onScroll === 'function' ) {
720
- props . onScroll ( e ) ;
721
- }
722
- if ( selectedSubSectionId ) {
723
- setSelectedSubSectionId ( undefined ) ;
746
+ prevScrollTop . current = e . target . scrollTop ;
747
+ if ( ! headerPinned ) {
748
+ setHeaderCollapsedInternal ( true ) ;
724
749
}
725
- if ( selectionScrollTimeout . current ) {
726
- clearTimeout ( selectionScrollTimeout . current ) ;
727
- }
728
- if ( ! headerPinned || e . target . scrollTop === 0 ) {
729
- objectPageRef . current ?. classList . remove ( classNames . headerCollapsed ) ;
730
- }
731
- if ( scrolledHeaderExpanded && e . target . scrollTop !== prevScrollTop . current ) {
732
- if ( e . target . scrollHeight - e . target . scrollTop === e . target . clientHeight ) {
733
- return ;
734
- }
735
- prevScrollTop . current = e . target . scrollTop ;
736
- if ( ! headerPinned ) {
737
- setHeaderCollapsedInternal ( true ) ;
738
- }
739
- setScrolledHeaderExpanded ( false ) ;
740
- }
741
- } ,
742
- [ topHeaderHeight , headerPinned , props . onScroll , scrolledHeaderExpanded , selectedSubSectionId ]
743
- ) ;
750
+ setScrolledHeaderExpanded ( false ) ;
751
+ }
752
+ } ;
744
753
745
754
const onHoverToggleButton = useCallback (
746
755
( e ) => {
0 commit comments