diff --git a/.changeset/yellow-hounds-provide.md b/.changeset/yellow-hounds-provide.md new file mode 100644 index 0000000000..f4a4016db7 --- /dev/null +++ b/.changeset/yellow-hounds-provide.md @@ -0,0 +1,5 @@ +--- +"nextra-theme-docs": patch +--- + +fix: show `Scroll to top` link `toc.backToTop` when `toc.float: false` is set diff --git a/packages/nextra-theme-docs/src/components/toc.tsx b/packages/nextra-theme-docs/src/components/toc.tsx index 7259b9e01d..29040b81a2 100644 --- a/packages/nextra-theme-docs/src/components/toc.tsx +++ b/packages/nextra-theme-docs/src/components/toc.tsx @@ -6,7 +6,7 @@ import { Anchor } from 'nextra/components' import type { FC } from 'react' import { useEffect, useRef } from 'react' import scrollIntoView from 'scroll-into-view-if-needed' -import { useActiveAnchor, useThemeConfig } from '../stores' +import { useActiveAnchor, useConfig, useThemeConfig } from '../stores' import { getGitIssueUrl, gitUrlParse } from '../utils' import { BackToTop } from './back-to-top' @@ -34,7 +34,10 @@ export const TOC: FC = ({ toc, filePath, pageTitle }) => { themeConfig.toc.extraContent || themeConfig.toc.backToTop - const hasHeadings = toc.length > 0 + const { activeType } = useConfig().normalizePagesResult + const anchors = themeConfig.toc.float || activeType === 'page' ? toc : [] + + const hasHeadings = anchors.length > 0 const activeIndex = toc.findIndex(({ id }) => id === activeSlug) useEffect(() => { @@ -71,7 +74,7 @@ export const TOC: FC = ({ toc, filePath, pageTitle }) => { 'nextra-mask' // for title/footer shadow )} > - {toc.map(({ id, value, depth }) => ( + {anchors.map(({ id, value, depth }) => (
  • {themeContext.toc && (