@@ -224,6 +224,7 @@ const ObjectPage = forwardRef<HTMLDivElement, ObjectPagePropTypes>((props, ref)
224224 const [ sectionSpacer , setSectionSpacer ] = useState ( 0 ) ;
225225 const [ currentTabModeSection , setCurrentTabModeSection ] = useState ( null ) ;
226226 const sections = mode === ObjectPageMode . IconTabBar ? currentTabModeSection : children ;
227+ const isScrolling = useRef < ReturnType < typeof setTimeout > | null > ( null ) ;
227228
228229 const deprecationNoticeDisplayed = useRef ( false ) ;
229230 useEffect ( ( ) => {
@@ -336,7 +337,6 @@ const ObjectPage = forwardRef<HTMLDivElement, ObjectPagePropTypes>((props, ref)
336337 } else {
337338 scrollToSectionById ( sectionId ) ;
338339 }
339- isProgrammaticallyScrolled . current = false ;
340340 } ;
341341
342342 const programmaticallySetSection = ( ) => {
@@ -388,6 +388,7 @@ const ObjectPage = forwardRef<HTMLDivElement, ObjectPagePropTypes>((props, ref)
388388 }
389389 return newSelectionSectionId ;
390390 } ) ;
391+ prevSelectedSectionId . current = newSelectionSectionId ;
391392 scrollEvent . current = targetEvent ;
392393 fireOnSelectedChangedEvent ( targetEvent , index , newSelectionSectionId , section ) ;
393394 } ;
@@ -448,6 +449,7 @@ const ObjectPage = forwardRef<HTMLDivElement, ObjectPagePropTypes>((props, ref)
448449 } ) ;
449450 if ( sectionId ) {
450451 setInternalSelectedSectionId ( sectionId ) ;
452+ prevSelectedSectionId . current = sectionId ;
451453 }
452454 }
453455 }
@@ -504,6 +506,7 @@ const ObjectPage = forwardRef<HTMLDivElement, ObjectPagePropTypes>((props, ref)
504506 if ( mode === ObjectPageMode . IconTabBar ) {
505507 const sectionId = e . detail . sectionId ;
506508 setInternalSelectedSectionId ( sectionId ) ;
509+ prevSelectedSectionId . current = sectionId ;
507510 const sectionNodes = objectPageRef . current ?. querySelectorAll (
508511 'section[data-component-name="ObjectPageSection"]'
509512 ) ;
@@ -552,11 +555,11 @@ const ObjectPage = forwardRef<HTMLDivElement, ObjectPagePropTypes>((props, ref)
552555 }
553556 return visibleSectionIds . current . has ( section . id ) ;
554557 } ) ;
555-
556- if ( sortedVisibleSections . length > 0 ) {
558+ if ( sortedVisibleSections . length > 0 && ! isProgrammaticallyScrolled . current ) {
557559 const section = sortedVisibleSections [ 0 ] ;
558560 const id = sortedVisibleSections [ 0 ] . id . slice ( 18 ) ;
559561 setInternalSelectedSectionId ( id ) ;
562+ prevSelectedSectionId . current = id ;
560563 debouncedOnSectionChange ( scrollEvent . current , currentIndex , id , section ) ;
561564 }
562565 } ) ;
@@ -707,40 +710,46 @@ const ObjectPage = forwardRef<HTMLDivElement, ObjectPagePropTypes>((props, ref)
707710 } ;
708711
709712 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 ) {
716744 return ;
717745 }
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 ) ;
724749 }
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+ } ;
744753
745754 const onHoverToggleButton = useCallback (
746755 ( e ) => {
0 commit comments