Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[core] Fix header link layout shift and clash #35626

Merged
merged 1 commit into from
Dec 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/src/modules/components/ApiPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ function Heading(props) {
return (
<Level id={hash}>
{getTranslatedHeader(t, hash)}
<a aria-labelledby={hash} className="anchor-link-style" href={`#${hash}`} tabIndex={-1}>
<a aria-labelledby={hash} className="anchor-link" href={`#${hash}`} tabIndex={-1}>
<svg>
<use xlinkHref="#anchor-link-icon" />
</svg>
Expand Down
2 changes: 1 addition & 1 deletion docs/src/modules/components/AppLayoutDocs.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const Main = styled('main', {
[theme.breakpoints.up('lg')]: {
width: 'calc(100% - var(--MuiDocs-navDrawer-width))',
},
'& .markdown-body .comment-link-style': {
'& .markdown-body .comment-link': {
display: 'inline-block',
},
}));
Expand Down
18 changes: 10 additions & 8 deletions docs/src/modules/components/MarkdownElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,25 +108,28 @@ const Root = styled('div')(
},
'& h1, & h2, & h3, & h4': {
position: 'relative',
paddingRight: 26 * 2 + 10,
'& code': {
fontSize: 'inherit',
lineHeight: 'inherit',
// Remove scroll on small screens.
wordBreak: 'break-all',
},
'& .anchor-link-style': {
'& .anchor-link': {
// To prevent the link to get the focus.
display: 'none',
},
'& a:not(.anchor-link-style):hover': {
'& a:not(.anchor-link):hover': {
color: 'currentColor',
borderBottom: '1px solid currentColor',
textDecoration: 'none',
},
'&:hover .anchor-link-style, & .comment-link-style': {
'&:hover .anchor-link, & .comment-link': {
lineHeight: '21.5px',
position: 'absolute',
textAlign: 'center',
marginLeft: 10,
marginTop: 5,
height: 26,
width: 26,
backgroundColor: `var(--muidocs-palette-primary-50, ${lightTheme.palette.primary[50]})`,
Expand All @@ -146,10 +149,9 @@ const Root = styled('div')(
pointerEvents: 'none',
},
},
'& .comment-link-style': {
display: 'none',
position: 'absolute',
top: `calc(50% - ${26 / 2}px)`,
'& .comment-link': {
display: 'none', // So we can have the comment button opt-in.
top: 0,
right: 0,
opacity: 0.5,
transition: theme.transitions.create('opacity', {
Expand Down Expand Up @@ -462,7 +464,7 @@ const Root = styled('div')(
color: `var(--muidocs-palette-grey-400, ${darkTheme.palette.grey[400]})`,
},
'& h1, & h2, & h3, & h4': {
'&:hover .anchor-link-style, & .comment-link-style': {
'&:hover .anchor-link, & .comment-link': {
color: `var(--muidocs-palette-text-secondary, ${darkTheme.palette.text.secondary})`,
backgroundColor: alpha(darkTheme.palette.primaryDark[800], 0.3),
borderColor: `var(--muidocs-palette-primaryDark-500, ${darkTheme.palette.primaryDark[500]})`,
Expand Down
4 changes: 2 additions & 2 deletions packages/markdown/parseMarkdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,10 +246,10 @@ function createRender(context) {
return [
`<h${level} id="${hash}">`,
headingHtml,
`<a aria-labelledby="${hash}" class="anchor-link-style" href="#${hash}" tabindex="-1">`,
`<a aria-labelledby="${hash}" class="anchor-link" href="#${hash}" tabindex="-1">`,
'<svg><use xlink:href="#anchor-link-icon" /></svg>',
'</a>',
`<button title="Post a comment" class="comment-link-style" data-feedback-hash="${hash}">`,
`<button title="Post a comment" class="comment-link" data-feedback-hash="${hash}">`,
'<svg><use xlink:href="#comment-link-icon" /></svg>',
`</button>`,
`</h${level}>`,
Expand Down