11import React , { useRef } from 'react' ;
2- import { css , cx } from '@leafygreen-ui/emotion' ;
2+ import { css , cx , keyframes } from '@leafygreen-ui/emotion' ;
33import { palette } from '@leafygreen-ui/palette' ;
44import { withTheme } from '../hooks/use-theme' ;
55import { spacing } from '@leafygreen-ui/tokens' ;
@@ -28,6 +28,15 @@ const scrollBoxStyles = css({
2828
2929const shadowHeight = spacing [ 4 ] ;
3030
31+ const fadeIn = keyframes ( {
32+ from : {
33+ opacity : 0 ,
34+ } ,
35+ to : {
36+ opacity : 1 ,
37+ } ,
38+ } ) ;
39+
3140const shadowContainerStyles = css ( {
3241 overflow : 'hidden' ,
3342 position : 'absolute' ,
@@ -38,6 +47,11 @@ const shadowContainerStyles = css({
3847 flex : 'none' ,
3948 zIndex : 1 ,
4049 pointerEvents : 'none' ,
50+ // Animation prevents possible flicker when in-view trigger that is
51+ // responsible for showing the shadow very quickly switches between being
52+ // hidden to being visible again (that is the case where we don't unmount
53+ // collection tabs and just use display: none to hide them)
54+ animation : `${ fadeIn } .1s linear` ,
4155} ) ;
4256
4357const boxShadow = ( color : string ) => `0px 2px ${ shadowHeight } px -1px ${ color } ` ;
@@ -100,6 +114,10 @@ function UnthemedWorkspaceContainer({
100114
101115 const [ scrollDetectionTrigger , triggerStillInView ] = useInView ( {
102116 root : scrollContainer . current ,
117+ // Prevents flicker on initial mount: when this component mounts we know for
118+ // sure that trigger in view as the trigger is at the very top of the
119+ // container
120+ initialInView : true ,
103121 } ) ;
104122
105123 return (
0 commit comments