@@ -25,12 +25,13 @@ import styles from './ObjectPage.jss';
25
25
import { ObjectPageAnchorButton } from './ObjectPageAnchorButton' ;
26
26
import { Button } from '@ui5/webcomponents-react/lib/Button' ;
27
27
import { CollapsedAvatar } from './CollapsedAvatar' ;
28
- import { ObjectPageScroller } from './scroll/ObjectPageScroller' ;
28
+ import { IScroller , ObjectPageScroller } from './scroll/ObjectPageScroller' ;
29
29
import { AvatarSize } from '@ui5/webcomponents-react/lib/AvatarSize' ;
30
30
import { ContentDensity } from '@ui5/webcomponents-react/lib/ContentDensity' ;
31
31
import '@ui5/webcomponents/dist/icons/navigation-up-arrow.js' ;
32
32
import { getScrollBarWidth } from '@ui5/webcomponents-react-base/lib/Utils' ;
33
33
import '@ui5/webcomponents/dist/icons/navigation-down-arrow.js' ;
34
+ import { ObjectPageSubSectionPropTypes } from '../ObjectPageSubSection' ;
34
35
35
36
export interface ObjectPagePropTypes extends CommonProps {
36
37
title ?: string ;
@@ -42,11 +43,13 @@ export interface ObjectPagePropTypes extends CommonProps {
42
43
children ?: ReactNode | ReactNodeArray ;
43
44
mode ?: ObjectPageMode ;
44
45
selectedSectionId ?: string ;
46
+ selectedSubSectionId ?: string ;
45
47
onSelectedSectionChanged ?: ( event : Event ) => void ;
46
48
showHideHeaderButton ?: boolean ;
47
49
alwaysShowContentHeader ?: boolean ;
48
50
noHeader ?: boolean ;
49
51
showTitleInHeaderContent ?: boolean ;
52
+ scrollerRef ?: RefObject < IScroller > ;
50
53
}
51
54
52
55
const useStyles = createUseStyles < JSSTheme , keyof ReturnType < typeof styles > > ( styles , { name : 'ObjectPage' } ) ;
@@ -81,11 +84,12 @@ const ObjectPage: FC<ObjectPagePropTypes> = forwardRef((props: ObjectPagePropTyp
81
84
selectedSectionId,
82
85
noHeader,
83
86
alwaysShowContentHeader,
84
- showTitleInHeaderContent
87
+ showTitleInHeaderContent,
88
+ scrollerRef
85
89
} = props ;
86
90
87
91
const [ selectedSectionIndex , setSelectedSectionIndex ] = useState ( findSectionIndexById ( children , selectedSectionId ) ) ;
88
- const [ selectedSubSectionId , setSelectedSubSectionId ] = useState ( null ) ;
92
+ const [ selectedSubSectionId , setSelectedSubSectionId ] = useState ( props . selectedSubSectionId ) ;
89
93
const [ expandHeaderActive , setExpandHeaderActive ] = useState ( false ) ;
90
94
const [ isMounted , setIsMounted ] = useState ( false ) ;
91
95
const [ collapsedHeader , setCollapsedHeader ] = useState ( false ) ;
@@ -104,7 +108,7 @@ const ObjectPage: FC<ObjectPagePropTypes> = forwardRef((props: ObjectPagePropTyp
104
108
const hideHeaderButtonPressed = useRef ( false ) ;
105
109
const stableContentOnScrollRef = useRef ( null ) ;
106
110
const stableBarOnScrollRef = useRef ( null ) ;
107
- const scroller = useRef ( null ) ;
111
+ const scroller = useConsolidatedRef ( scrollerRef ) ;
108
112
const [ scrollbarWidth , setScrollbarWidth ] = useState ( defaultScrollbarWidth ) ;
109
113
110
114
const classes = useStyles ( ) ;
@@ -353,11 +357,41 @@ const ObjectPage: FC<ObjectPagePropTypes> = forwardRef((props: ObjectPagePropTyp
353
357
} , [ noHeader , mode , alwaysShowContentHeader ] ) ;
354
358
355
359
useEffect ( ( ) => {
356
- if ( selectedSubSectionId && mode === ObjectPageMode . IconTabBar && scroller . current ) {
357
- scroller . current . scrollToElementById ( `ObjectPageSubSection-${ selectedSubSectionId } ` , collapsedHeader ? 45 : 0 ) ;
360
+ if ( selectedSubSectionId && scroller . current ) {
361
+ scroller . current . scrollToElementById ( `ObjectPageSubSection-${ selectedSubSectionId } ` , 45 ) ;
358
362
}
359
363
} , [ selectedSubSectionId ] ) ;
360
364
365
+ useEffect ( ( ) => {
366
+ if ( props . selectedSubSectionId ) {
367
+ setSelectedSubSectionId ( props . selectedSubSectionId ) ;
368
+ if ( mode === ObjectPageMode . IconTabBar ) {
369
+ // get section index
370
+
371
+ let index ;
372
+ React . Children . toArray ( children ) . forEach ( ( section , sectionIndex ) => {
373
+ if ( React . isValidElement ( section ) && section . props && section . props . children ) {
374
+ React . Children . toArray ( section . props . children ) . forEach (
375
+ ( subSection : ReactElement < ObjectPageSubSectionPropTypes > ) => {
376
+ if (
377
+ React . isValidElement ( subSection ) &&
378
+ subSection . props &&
379
+ subSection . props . id === props . selectedSubSectionId
380
+ ) {
381
+ index = sectionIndex ;
382
+ }
383
+ }
384
+ ) ;
385
+ }
386
+ } ) ;
387
+
388
+ if ( index ) {
389
+ setSelectedSectionIndex ( index ) ;
390
+ }
391
+ }
392
+ }
393
+ } , [ props . selectedSubSectionId , scroller . current , setSelectedSectionIndex , setSelectedSubSectionId , children , mode ] ) ;
394
+
361
395
useEffect ( ( ) => {
362
396
if ( ! isMounted && selectedSectionIndex < 1 ) return ;
363
397
@@ -366,7 +400,7 @@ const ObjectPage: FC<ObjectPagePropTypes> = forwardRef((props: ObjectPagePropTyp
366
400
// @ts -ignore
367
401
const id = Children . toArray ( children ) [ selectedSectionIndex ] . props . id ;
368
402
if ( id ) {
369
- scroller . current . scrollToElementById ( `ObjectPageSection-${ id } ` , collapsedHeader ? 45 : 0 ) ;
403
+ scroller . current . scrollToElementById ( `ObjectPageSection-${ id } ` , 45 ) ;
370
404
}
371
405
} else {
372
406
scroller . current . scrollToTop ( ) ;
0 commit comments