1
1
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
// SPDX-License-Identifier: Apache-2.0
3
- import React , { useEffect , useImperativeHandle , useLayoutEffect , useRef , useState } from 'react' ;
3
+ import React , { useEffect , useImperativeHandle , useState } from 'react' ;
4
4
5
5
import { useStableCallback } from '@cloudscape-design/component-toolkit/internal' ;
6
6
@@ -9,7 +9,6 @@ import { SplitPanelSideToggleProps } from '../../internal/context/split-panel-co
9
9
import { fireNonCancelableEvent } from '../../internal/events' ;
10
10
import { useControllable } from '../../internal/hooks/use-controllable' ;
11
11
import { useIntersectionObserver } from '../../internal/hooks/use-intersection-observer' ;
12
- import { useMergeRefs } from '../../internal/hooks/use-merge-refs' ;
13
12
import { useMobile } from '../../internal/hooks/use-mobile' ;
14
13
import { useUniqueId } from '../../internal/hooks/use-unique-id' ;
15
14
import { useGetGlobalBreadcrumbs } from '../../internal/plugins/helpers/use-global-breadcrumbs' ;
@@ -79,8 +78,6 @@ const AppLayoutVisualRefreshToolbar = React.forwardRef<AppLayoutProps.Ref, AppLa
79
78
const [ notificationsHeight , setNotificationsHeight ] = useState ( 0 ) ;
80
79
const [ navigationAnimationDisabled , setNavigationAnimationDisabled ] = useState ( true ) ;
81
80
const [ splitPanelAnimationDisabled , setSplitPanelAnimationDisabled ] = useState ( true ) ;
82
- const [ isNested , setIsNested ] = useState ( false ) ;
83
- const rootRef = useRef < HTMLDivElement > ( null ) ;
84
81
85
82
const [ toolsOpen = false , setToolsOpen ] = useControllable ( controlledToolsOpen , onToolsChange , false , {
86
83
componentName : 'AppLayout' ,
@@ -435,45 +432,16 @@ const AppLayoutVisualRefreshToolbar = React.forwardRef<AppLayoutProps.Ref, AppLa
435
432
placement . inlineSize ,
436
433
] ) ;
437
434
438
- /**
439
- * Returns true if the AppLayout is nested
440
- * Does not apply to iframe
441
- */
442
- const getIsNestedInAppLayout = ( element : HTMLElement | null ) : boolean => {
443
- let currentElement : Element | null = element ?. parentElement ?? null ;
444
-
445
- // this traverse is needed only for JSDOM
446
- // in real browsers the globalVar will be propagated to all descendants and this loops exits after initial iteration
447
- while ( currentElement ) {
448
- if ( getComputedStyle ( currentElement ) . getPropertyValue ( globalVars . stickyVerticalTopOffset ) ) {
449
- return true ;
450
- }
451
- currentElement = currentElement . parentElement ;
452
- }
453
-
454
- return false ;
455
- } ;
456
-
457
- useLayoutEffect ( ( ) => {
458
- if ( ! hasToolbar ) {
459
- setIsNested ( getIsNestedInAppLayout ( rootRef . current ) ) ;
460
- }
461
- } , [ hasToolbar ] ) ;
462
-
463
435
return (
464
436
< >
465
437
{ /* Rendering a hidden copy of breadcrumbs to trigger their deduplication */ }
466
438
{ ! hasToolbar && breadcrumbs ? < ScreenreaderOnly > { breadcrumbs } </ ScreenreaderOnly > : null }
467
439
< SkeletonLayout
468
- ref = { useMergeRefs ( intersectionObserverRef , rootRef ) }
440
+ ref = { intersectionObserverRef }
469
441
style = { {
442
+ [ globalVars . stickyVerticalTopOffset ] : `${ verticalOffsets . header } px` ,
443
+ [ globalVars . stickyVerticalBottomOffset ] : `${ placement . insetBlockEnd } px` ,
470
444
paddingBlockEnd : splitPanelOpen && splitPanelPosition === 'bottom' ? splitPanelReportedSize : '' ,
471
- ...( hasToolbar || ! isNested
472
- ? {
473
- [ globalVars . stickyVerticalTopOffset ] : `${ verticalOffsets . header } px` ,
474
- [ globalVars . stickyVerticalBottomOffset ] : `${ placement . insetBlockEnd } px` ,
475
- }
476
- : { } ) ,
477
445
...( ! isMobile ? { minWidth : `${ minContentWidth } px` } : { } ) ,
478
446
} }
479
447
toolbar = {
0 commit comments