mirror of
https://github.com/facebook/docusaurus.git
synced 2025-12-25 17:22:50 +00:00
fix(theme): Fix footnote ref scrolling behind the navbar when footnote back reference clicked (#11289)
Some checks are pending
Argos CI / take-screenshots (push) Waiting to run
Build Hash Router / Build Hash Router (push) Waiting to run
Canary Release / Publish Canary (push) Waiting to run
CodeQL / Analyze (javascript) (push) Waiting to run
Continuous Releases / Continuous Releases (push) Waiting to run
E2E Tests / E2E — Yarn v1 (18.0) (push) Waiting to run
E2E Tests / E2E — Yarn v1 (20) (push) Waiting to run
E2E Tests / E2E — Yarn v1 (22) (push) Waiting to run
E2E Tests / E2E — Yarn v1 (24) (push) Waiting to run
E2E Tests / E2E — Yarn v1 Windows (push) Waiting to run
E2E Tests / E2E — Yarn Berry (node-modules, -s) (push) Waiting to run
E2E Tests / E2E — Yarn Berry (node-modules, -st) (push) Waiting to run
E2E Tests / E2E — Yarn Berry (pnp, -s) (push) Waiting to run
E2E Tests / E2E — Yarn Berry (pnp, -st) (push) Waiting to run
E2E Tests / E2E — npm (push) Waiting to run
E2E Tests / E2E — pnpm (push) Waiting to run
Some checks are pending
Argos CI / take-screenshots (push) Waiting to run
Build Hash Router / Build Hash Router (push) Waiting to run
Canary Release / Publish Canary (push) Waiting to run
CodeQL / Analyze (javascript) (push) Waiting to run
Continuous Releases / Continuous Releases (push) Waiting to run
E2E Tests / E2E — Yarn v1 (18.0) (push) Waiting to run
E2E Tests / E2E — Yarn v1 (20) (push) Waiting to run
E2E Tests / E2E — Yarn v1 (22) (push) Waiting to run
E2E Tests / E2E — Yarn v1 (24) (push) Waiting to run
E2E Tests / E2E — Yarn v1 Windows (push) Waiting to run
E2E Tests / E2E — Yarn Berry (node-modules, -s) (push) Waiting to run
E2E Tests / E2E — Yarn Berry (node-modules, -st) (push) Waiting to run
E2E Tests / E2E — Yarn Berry (pnp, -s) (push) Waiting to run
E2E Tests / E2E — Yarn Berry (pnp, -st) (push) Waiting to run
E2E Tests / E2E — npm (push) Waiting to run
E2E Tests / E2E — pnpm (push) Waiting to run
This commit is contained in:
parent
e82cd48842
commit
1592094206
|
|
@ -1040,7 +1040,9 @@ declare module '@theme/SkipToContent' {
|
|||
declare module '@theme/MDXComponents/A' {
|
||||
import type {ComponentProps, ReactNode} from 'react';
|
||||
|
||||
export interface Props extends ComponentProps<'a'> {}
|
||||
export interface Props extends ComponentProps<'a'> {
|
||||
'data-footnote-ref'?: true;
|
||||
}
|
||||
|
||||
export default function MDXA(props: Props): ReactNode;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,14 +0,0 @@
|
|||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import React, {type ReactNode} from 'react';
|
||||
import Link from '@docusaurus/Link';
|
||||
import type {Props} from '@theme/MDXComponents/A';
|
||||
|
||||
export default function MDXA(props: Props): ReactNode {
|
||||
return <Link {...props} />;
|
||||
}
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import React, {type ReactNode} from 'react';
|
||||
import clsx from 'clsx';
|
||||
import Link from '@docusaurus/Link';
|
||||
import {useThemeConfig} from '@docusaurus/theme-common';
|
||||
import type {Props} from '@theme/MDXComponents/A';
|
||||
import styles from './styles.module.css';
|
||||
|
||||
function isFootnoteRef(props: Props) {
|
||||
return props['data-footnote-ref'] === true;
|
||||
}
|
||||
|
||||
function FootnoteRefLink(props: Props) {
|
||||
const {
|
||||
navbar: {hideOnScroll},
|
||||
} = useThemeConfig();
|
||||
return (
|
||||
<Link
|
||||
{...props}
|
||||
className={clsx(
|
||||
hideOnScroll
|
||||
? styles.footnoteRefHideOnScrollNavbar
|
||||
: styles.footnoteRefStickyNavbar,
|
||||
|
||||
props.className,
|
||||
)}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
export default function MDXA(props: Props): ReactNode {
|
||||
if (isFootnoteRef(props)) {
|
||||
return <FootnoteRefLink {...props} />;
|
||||
}
|
||||
return <Link {...props} />;
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
/*
|
||||
When the navbar is sticky, ensure that on footnote click,
|
||||
the browser does not scroll to the ref behind the navbar
|
||||
See https://github.com/facebook/docusaurus/issues/11232
|
||||
See also headings case https://x.com/JoshWComeau/status/1332015868725891076
|
||||
*/
|
||||
.footnoteRefStickyNavbar {
|
||||
scroll-margin-top: calc(var(--ifm-navbar-height) + 0.5rem);
|
||||
}
|
||||
|
||||
.footnoteRefHideOnScrollNavbar {
|
||||
scroll-margin-top: 0.5rem;
|
||||
}
|
||||
Loading…
Reference in New Issue