55 debounce ,
66 enrichEventWithDetails ,
77 ThemingParameters ,
8+ useIsomorphicLayoutEffect ,
89 useStylesheet ,
910 useSyncRef
1011} from '@ui5/webcomponents-react-base' ;
@@ -108,6 +109,7 @@ const ObjectPage = forwardRef<ObjectPageDomRef, ObjectPagePropTypes>((props, ref
108109 const prevInternalSelectedSectionId = useRef ( internalSelectedSectionId ) ;
109110 const fireOnSelectedChangedEvent = ( targetEvent , index , id , section ) => {
110111 if ( typeof onSelectedSectionChange === 'function' && targetEvent && prevInternalSelectedSectionId . current !== id ) {
112+ console . log ( 'FIRE!!!' ) ;
111113 onSelectedSectionChange (
112114 enrichEventWithDetails ( targetEvent , {
113115 selectedSectionIndex : parseInt ( index , 10 ) ,
@@ -249,18 +251,23 @@ const ObjectPage = forwardRef<ObjectPageDomRef, ObjectPagePropTypes>((props, ref
249251 fireOnSelectedChangedEvent ( targetEvent , index , newSelectionSectionId , section ) ;
250252 } ;
251253
252- useEffect ( ( ) => {
254+ useIsomorphicLayoutEffect ( ( ) => {
253255 if ( selectedSectionId ) {
256+ const fireSelectEvent = ( ) => {
257+ const selectedSection = getSectionElementById ( objectPageRef . current , false , selectedSectionId ) ;
258+ if ( selectedSection ) {
259+ const selectedSectionIndex = Array . from (
260+ selectedSection . parentElement . querySelectorAll ( ':scope > [data-component-name="ObjectPageSection"]' )
261+ ) . indexOf ( selectedSection ) ;
262+ handleOnSectionSelected ( { } , selectedSectionId , selectedSectionIndex , selectedSection ) ;
263+ }
264+ } ;
254265 if ( mode === ObjectPageMode . IconTabBar ) {
255266 setInternalSelectedSectionId ( selectedSectionId ) ;
256- return ;
257- }
258- const selectedSection = getSectionElementById ( objectPageRef . current , false , selectedSectionId ) ;
259- if ( selectedSection ) {
260- const selectedSectionIndex = Array . from (
261- selectedSection . parentElement . querySelectorAll ( ':scope > [data-component-name="ObjectPageSection"]' )
262- ) . indexOf ( selectedSection ) ;
263- handleOnSectionSelected ( { } , selectedSectionId , selectedSectionIndex , selectedSection ) ;
267+ // In TabBar mode the section is only rendered when selected, therefore delay firing the event until the section is available in the DOM
268+ setTimeout ( fireSelectEvent ) ;
269+ } else {
270+ fireSelectEvent ( ) ;
264271 }
265272 }
266273 } , [ selectedSectionId , mode ] ) ;
@@ -300,6 +307,7 @@ const ObjectPage = forwardRef<ObjectPageDomRef, ObjectPagePropTypes>((props, ref
300307 }
301308 } , [ headerPinned , topHeaderHeight ] ) ;
302309
310+ const isInitialTabBarMode = useRef ( true ) ;
303311 useEffect ( ( ) => {
304312 if ( ! isMounted ) {
305313 requestAnimationFrame ( ( ) => setIsMounted ( true ) ) ;
@@ -311,24 +319,33 @@ const ObjectPage = forwardRef<ObjectPageDomRef, ObjectPagePropTypes>((props, ref
311319 isProgrammaticallyScrolled . current = true ;
312320 if ( mode === ObjectPageMode . IconTabBar ) {
313321 let sectionId : string ;
314- childrenArray . forEach ( ( section ) => {
322+ let curSection : ReactElement ;
323+ let sectionIndex : number = - 1 ;
324+ childrenArray . forEach ( ( section , index ) => {
315325 if ( isValidElement ( section ) && section . props && section . props . children ) {
316326 safeGetChildrenArray ( section . props . children ) . forEach ( ( subSection ) => {
317327 if (
318328 isValidElement ( subSection ) &&
319329 subSection . props &&
320330 ( subSection as ReactElement < ObjectPageSubSectionPropTypes > ) . props . id === props . selectedSubSectionId
321331 ) {
332+ curSection = section ;
322333 sectionId = section . props ?. id ;
334+ sectionIndex = index ;
323335 }
324336 } ) ;
325337 }
326338 } ) ;
327339 if ( sectionId ) {
340+ if ( ! isInitialTabBarMode . current ) {
341+ //In TabBar mode the section is often not scrolled when subsection changes, thus the onSelectedSectionChange isn't fired
342+ debouncedOnSectionChange ( { } , sectionIndex , sectionId , curSection ) ;
343+ }
328344 setInternalSelectedSectionId ( sectionId ) ;
329345 }
330346 }
331347 }
348+ isInitialTabBarMode . current = false ;
332349 } , [ props . selectedSubSectionId , isMounted ] ) ;
333350
334351 const tabContainerContainerRef = useRef ( null ) ;
0 commit comments