55 debounce ,
66 enrichEventWithDetails ,
77 ThemingParameters ,
8+ useIsomorphicLayoutEffect ,
89 useStylesheet ,
910 useSyncRef
1011} from '@ui5/webcomponents-react-base' ;
@@ -249,18 +250,23 @@ const ObjectPage = forwardRef<ObjectPageDomRef, ObjectPagePropTypes>((props, ref
249250 fireOnSelectedChangedEvent ( targetEvent , index , newSelectionSectionId , section ) ;
250251 } ;
251252
252- useEffect ( ( ) => {
253+ useIsomorphicLayoutEffect ( ( ) => {
253254 if ( selectedSectionId ) {
255+ const fireSelectEvent = ( ) => {
256+ const selectedSection = getSectionElementById ( objectPageRef . current , false , selectedSectionId ) ;
257+ if ( selectedSection ) {
258+ const selectedSectionIndex = Array . from (
259+ selectedSection . parentElement . querySelectorAll ( ':scope > [data-component-name="ObjectPageSection"]' )
260+ ) . indexOf ( selectedSection ) ;
261+ handleOnSectionSelected ( { } , selectedSectionId , selectedSectionIndex , selectedSection ) ;
262+ }
263+ } ;
254264 if ( mode === ObjectPageMode . IconTabBar ) {
255265 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 ) ;
266+ // In TabBar mode the section is only rendered when selected, therefore delay firing the event until the section is available in the DOM
267+ setTimeout ( fireSelectEvent ) ;
268+ } else {
269+ fireSelectEvent ( ) ;
264270 }
265271 }
266272 } , [ selectedSectionId , mode ] ) ;
@@ -300,6 +306,7 @@ const ObjectPage = forwardRef<ObjectPageDomRef, ObjectPagePropTypes>((props, ref
300306 }
301307 } , [ headerPinned , topHeaderHeight ] ) ;
302308
309+ const isInitialTabBarMode = useRef ( true ) ;
303310 useEffect ( ( ) => {
304311 if ( ! isMounted ) {
305312 requestAnimationFrame ( ( ) => setIsMounted ( true ) ) ;
@@ -311,24 +318,33 @@ const ObjectPage = forwardRef<ObjectPageDomRef, ObjectPagePropTypes>((props, ref
311318 isProgrammaticallyScrolled . current = true ;
312319 if ( mode === ObjectPageMode . IconTabBar ) {
313320 let sectionId : string ;
314- childrenArray . forEach ( ( section ) => {
321+ let curSection : ReactElement ;
322+ let sectionIndex : number = - 1 ;
323+ childrenArray . forEach ( ( section , index ) => {
315324 if ( isValidElement ( section ) && section . props && section . props . children ) {
316325 safeGetChildrenArray ( section . props . children ) . forEach ( ( subSection ) => {
317326 if (
318327 isValidElement ( subSection ) &&
319328 subSection . props &&
320329 ( subSection as ReactElement < ObjectPageSubSectionPropTypes > ) . props . id === props . selectedSubSectionId
321330 ) {
331+ curSection = section ;
322332 sectionId = section . props ?. id ;
333+ sectionIndex = index ;
323334 }
324335 } ) ;
325336 }
326337 } ) ;
327338 if ( sectionId ) {
339+ if ( ! isInitialTabBarMode . current ) {
340+ //In TabBar mode the section is often not scrolled when subsection changes, thus the onSelectedSectionChange isn't fired
341+ debouncedOnSectionChange ( { } , sectionIndex , sectionId , curSection ) ;
342+ }
328343 setInternalSelectedSectionId ( sectionId ) ;
329344 }
330345 }
331346 }
347+ isInitialTabBarMode . current = false ;
332348 } , [ props . selectedSubSectionId , isMounted ] ) ;
333349
334350 const tabContainerContainerRef = useRef ( null ) ;
0 commit comments