@@ -7,16 +7,15 @@ import { useTranslation } from 'react-i18next';
7
7
import type { LoaderStatus } from '../types' ;
8
8
9
9
const LOADER_HEIGHT = 176 ;
10
- const LOADER_BOTTOM_OFFSET = 32 ;
11
- const FORM_TOP_OFFSET = 120 + 68 ; // navbar + prev path heights
12
- const LAUNCH_BUTTON_HEIGHT = 40 ;
10
+ const LOADER_OFFSET = 32 ;
13
11
14
12
type StdcmLoaderProps = {
15
13
cancelStdcmRequest : ( ) => void ;
16
14
launchButtonRef : RefObject < HTMLDivElement > ;
15
+ formRef : RefObject < HTMLDivElement > ;
17
16
} ;
18
17
19
- const StdcmLoader = ( { cancelStdcmRequest, launchButtonRef } : StdcmLoaderProps ) => {
18
+ const StdcmLoader = ( { cancelStdcmRequest, launchButtonRef, formRef } : StdcmLoaderProps ) => {
20
19
const { t } = useTranslation ( 'stdcm' ) ;
21
20
const loaderRef = useRef < HTMLDivElement > ( null ) ;
22
21
@@ -31,13 +30,13 @@ const StdcmLoader = ({ cancelStdcmRequest, launchButtonRef }: StdcmLoaderProps)
31
30
useEffect ( ( ) => {
32
31
// Depending on the scroll, change the position of the loader between fixed, sticky or absolute
33
32
const handleScroll = ( ) => {
34
- if ( ! loaderRef . current || ! launchButtonRef . current ) return ;
33
+ if ( ! loaderRef . current || ! launchButtonRef . current || ! formRef . current ) return ;
35
34
36
35
const { scrollY, innerHeight } = window ;
37
36
38
37
const isLoaderFitting =
39
38
innerHeight - launchButtonRef . current . getBoundingClientRect ( ) . top >
40
- LOADER_HEIGHT + LOADER_BOTTOM_OFFSET ;
39
+ LOADER_HEIGHT + LOADER_OFFSET ;
41
40
42
41
// Loader doesn't fit between the bottom of the form and bottom of the viewport
43
42
if ( ! isLoaderFitting ) {
@@ -48,9 +47,12 @@ const StdcmLoader = ({ cancelStdcmRequest, launchButtonRef }: StdcmLoaderProps)
48
47
return ;
49
48
}
50
49
51
- const currentFormHeight = loaderRef . current . parentElement ! . clientHeight ;
50
+ const currentFormHeight = formRef . current . clientHeight ;
51
+ const topFormPosition = formRef . current . getBoundingClientRect ( ) . top ;
52
+ const launchButtonHeight = launchButtonRef . current . clientHeight ;
52
53
const shouldLoaderStickTop =
53
- scrollY > currentFormHeight + FORM_TOP_OFFSET - LAUNCH_BUTTON_HEIGHT ;
54
+ scrollY >
55
+ currentFormHeight + scrollY + topFormPosition - launchButtonHeight - LOADER_OFFSET ;
54
56
55
57
// Loader reaches the top of the screen minus its top offset
56
58
if ( shouldLoaderStickTop ) {
0 commit comments