1
- import { useState , useEffect } from 'react'
1
+ import { useState , useEffect , useLayoutEffect } from 'react'
2
2
import cx from 'classnames'
3
3
import { ChevronUpIcon } from '@primer/octicons-react'
4
4
import styles from './ScrollButton.module.scss'
@@ -12,6 +12,7 @@ export type ScrollButtonPropsT = {
12
12
13
13
export const ScrollButton = ( { className, ariaLabel } : ScrollButtonPropsT ) => {
14
14
const [ show , setShow ] = useState ( false )
15
+ const [ isTallEnough , setIsTallEnough ] = useState ( false )
15
16
16
17
useEffect ( ( ) => {
17
18
// We cannot determine document.documentElement.scrollTop height because we set the height: 100vh and set overflow to auto to keep the header sticky
@@ -33,13 +34,27 @@ export const ScrollButton = ({ className, ariaLabel }: ScrollButtonPropsT) => {
33
34
}
34
35
} , [ ] )
35
36
37
+ // If the window isn't tall enough, the scroll button will hide some of the content
38
+ // A11y issue 8822
39
+ useLayoutEffect ( ( ) => {
40
+ function updateDocumentSize ( ) {
41
+ setIsTallEnough ( document . documentElement . clientHeight > 400 )
42
+ }
43
+ updateDocumentSize ( )
44
+ window . addEventListener ( 'resize' , updateDocumentSize )
45
+ return ( ) => window . removeEventListener ( 'resize' , updateDocumentSize )
46
+ } , [ ] )
47
+
36
48
const onClick = ( ) => {
37
49
document ?. getElementById ( 'github-logo' ) ?. focus ( )
38
50
document ?. getElementById ( 'main-content' ) ?. scrollIntoView ( )
39
51
}
40
52
41
53
return (
42
- < div role = "tooltip" className = { cx ( className , transition200 , show ? opacity100 : opacity0 ) } >
54
+ < div
55
+ role = "tooltip"
56
+ className = { cx ( className , transition200 , show && isTallEnough ? opacity100 : opacity0 ) }
57
+ >
43
58
< button
44
59
onClick = { onClick }
45
60
className = { cx (
0 commit comments