File tree 2 files changed +21
-3
lines changed
2 files changed +21
-3
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ ' nextra-theme-docs ' : patch
3
+ ---
4
+
5
+ fixes case when setting ` disabled: true ` on the scroll to top button prevents scrolling to most top
6
+
7
+ scroll to most top in toc element too
Original file line number Diff line number Diff line change 1
1
import cn from 'clsx'
2
2
import { ArrowRightIcon } from 'nextra/icons'
3
- import type { ReactElement } from 'react'
3
+ import type { ComponentProps , ReactElement } from 'react'
4
4
5
- function scrollToTop ( ) {
6
- window . scrollTo ( { top : 0 , behavior : 'smooth' } )
5
+ const SCROLL_TO_OPTIONS = { top : 0 , behavior : 'smooth' } as const
6
+
7
+ const scrollToTop : ComponentProps < 'button' > [ 'onClick' ] = event => {
8
+ const buttonElement = event . target as HTMLButtonElement
9
+ const tocElement = buttonElement . parentElement !
10
+ . parentElement as HTMLDivElement
11
+
12
+ window . scrollTo ( SCROLL_TO_OPTIONS )
13
+ tocElement . scrollTo ( SCROLL_TO_OPTIONS )
14
+
15
+ // Fixes https://github.com/facebook/react/issues/20770
16
+ // Fixes https://github.com/shuding/nextra/issues/2917
17
+ buttonElement . disabled = true
7
18
}
8
19
9
20
export function BackToTop ( {
You can’t perform that action at this time.
0 commit comments