Skip to content

Commit

Permalink
aa
Browse files Browse the repository at this point in the history
  • Loading branch information
dimaMachina committed Jul 19, 2024
1 parent 6f0817c commit f7ed0ca
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
7 changes: 7 additions & 0 deletions .changeset/brave-hats-flow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'nextra-theme-docs': patch
---

fixes case when setting `disabled: true` on the scroll to top button prevents scrolling to most top

scroll to most top in toc element too
17 changes: 14 additions & 3 deletions packages/nextra-theme-docs/src/components/back-to-top.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
import cn from 'clsx'
import { ArrowRightIcon } from 'nextra/icons'
import type { ReactElement } from 'react'
import type { ComponentProps, ReactElement } from 'react'

function scrollToTop() {
window.scrollTo({ top: 0, behavior: 'smooth' })
const SCROLL_TO_OPTIONS = { top: 0, behavior: 'smooth' } as const

const scrollToTop: ComponentProps<'button'>['onClick'] = event => {
const buttonElement = event.target as HTMLButtonElement
const tocElement = buttonElement.parentElement!
.parentElement as HTMLDivElement

window.scrollTo(SCROLL_TO_OPTIONS)
tocElement.scrollTo(SCROLL_TO_OPTIONS)

// Fixes https://github.com/facebook/react/issues/20770
// Fixes https://github.com/shuding/nextra/issues/2917
buttonElement.disabled = true
}

export function BackToTop({
Expand Down

0 comments on commit f7ed0ca

Please sign in to comment.