Skip to content

Commit 276c82e

Browse files
authored
Merge pull request #247 from rvsia/fixHeadersAgain
Fix headers again
2 parents 36ef4da + 74ee282 commit 276c82e

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

packages/react-renderer-demo/src/app/src/components/mdx/mdx-components.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,9 @@ const CodeEditor = dynamic(import('../code-editor'), {
2121
});
2222

2323
const useHeadingStyles = makeStyles(() => ({
24-
anchorOffset: {
24+
anchor: {
2525
textDecoration: 'none',
2626
color: 'inherit',
27-
paddingTop: 92, // compensate for fixed header size and spacing
28-
marginTop: -92, // compensate for fixed header size and spacing
29-
position: 'relative',
30-
display: 'block',
3127
},
3228
heading: {
3329
'& button': {
@@ -37,6 +33,10 @@ const useHeadingStyles = makeStyles(() => ({
3733
visibility: 'initial',
3834
},
3935
},
36+
offset: {
37+
paddingTop: 92, // compensate for fixed header size and spacing
38+
marginTop: -92, // compensate for fixed header size and spacing
39+
},
4040
}));
4141

4242
const Heading = ({ level, children, variant, component, ...rest }) => {
@@ -45,17 +45,19 @@ const Heading = ({ level, children, variant, component, ...rest }) => {
4545
const id = headerToId(children);
4646
const path = `${router.pathname}#${id}`;
4747
return (
48-
<a id={ id } href={ path } className={ classes.anchorOffset } data-mdlink="md-heading">
48+
<div id={ id } className={ classes.offset } data-scroll="true">
4949
<Typography
5050
id={ `heading-${id}` }
5151
className={ classes.heading }
5252
variant={ `h${level}` }
5353
component={ component }
5454
>
55-
{ children }
56-
<ShareButton path={ path }/>
55+
<a href={ path } className={ classes.anchor } data-mdlink="md-heading">
56+
{ children }
57+
<ShareButton path={ path }/>
58+
</a>
5759
</Typography>
58-
</a>
60+
</div>
5961
);
6062
};
6163

packages/react-renderer-demo/src/app/src/helpers/list-of-contents.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ const ListOfContents = ({ file }) => {
9393
const scrollListener = (setActive) => {
9494
const min = -10;
9595
const max = 20;
96-
const elem = Array.from(document.querySelectorAll('[data-mdlink]'))
96+
const elem = Array.from(document.querySelectorAll('[data-scroll]'))
9797
.find(elem => {
9898
const { top } = elem.getBoundingClientRect();
9999
return top > min && top < max;

0 commit comments

Comments
 (0)