5
5
debounce ,
6
6
enrichEventWithDetails ,
7
7
ThemingParameters ,
8
+ useIsomorphicLayoutEffect ,
8
9
useStylesheet ,
9
10
useSyncRef
10
11
} from '@ui5/webcomponents-react-base' ;
@@ -249,18 +250,23 @@ const ObjectPage = forwardRef<ObjectPageDomRef, ObjectPagePropTypes>((props, ref
249
250
fireOnSelectedChangedEvent ( targetEvent , index , newSelectionSectionId , section ) ;
250
251
} ;
251
252
252
- useEffect ( ( ) => {
253
+ useIsomorphicLayoutEffect ( ( ) => {
253
254
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
+ } ;
254
264
if ( mode === ObjectPageMode . IconTabBar ) {
255
265
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 ( ) ;
264
270
}
265
271
}
266
272
} , [ selectedSectionId , mode ] ) ;
@@ -300,6 +306,7 @@ const ObjectPage = forwardRef<ObjectPageDomRef, ObjectPagePropTypes>((props, ref
300
306
}
301
307
} , [ headerPinned , topHeaderHeight ] ) ;
302
308
309
+ const isInitialTabBarMode = useRef ( true ) ;
303
310
useEffect ( ( ) => {
304
311
if ( ! isMounted ) {
305
312
requestAnimationFrame ( ( ) => setIsMounted ( true ) ) ;
@@ -311,24 +318,33 @@ const ObjectPage = forwardRef<ObjectPageDomRef, ObjectPagePropTypes>((props, ref
311
318
isProgrammaticallyScrolled . current = true ;
312
319
if ( mode === ObjectPageMode . IconTabBar ) {
313
320
let sectionId : string ;
314
- childrenArray . forEach ( ( section ) => {
321
+ let curSection : ReactElement ;
322
+ let sectionIndex : number = - 1 ;
323
+ childrenArray . forEach ( ( section , index ) => {
315
324
if ( isValidElement ( section ) && section . props && section . props . children ) {
316
325
safeGetChildrenArray ( section . props . children ) . forEach ( ( subSection ) => {
317
326
if (
318
327
isValidElement ( subSection ) &&
319
328
subSection . props &&
320
329
( subSection as ReactElement < ObjectPageSubSectionPropTypes > ) . props . id === props . selectedSubSectionId
321
330
) {
331
+ curSection = section ;
322
332
sectionId = section . props ?. id ;
333
+ sectionIndex = index ;
323
334
}
324
335
} ) ;
325
336
}
326
337
} ) ;
327
338
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
+ }
328
343
setInternalSelectedSectionId ( sectionId ) ;
329
344
}
330
345
}
331
346
}
347
+ isInitialTabBarMode . current = false ;
332
348
} , [ props . selectedSubSectionId , isMounted ] ) ;
333
349
334
350
const tabContainerContainerRef = useRef ( null ) ;
0 commit comments