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

[docs-infra] Fix broken anchor button when header has a link #43598

Merged

Conversation

cherniavskii
Copy link
Member

In MUI X, we often have links in the header marking the Plan.
It turns out, the anchor button doesn't work if the header contains a link – see https://deploy-preview-14443--material-ui-x.netlify.app/x/react-data-grid/#commercial-licenses

This PR fixes the issue.

@cherniavskii cherniavskii added the scope: docs-infra Specific to the docs-infra product label Sep 3, 2024
@cherniavskii cherniavskii requested a review from a team September 3, 2024 19:54
@mui-bot
Copy link

mui-bot commented Sep 3, 2024

Netlify deploy preview

https://deploy-preview-43598--material-ui.netlify.app/

Bundle size report

No bundle size changes (Toolpad)
No bundle size changes

Generated by 🚫 dangerJS against 547c05a

@oliviertassinari oliviertassinari added the bug 🐛 Something doesn't work label Sep 3, 2024
headingHtml.includes('<a ')
? [
// Avoid breaking the anchor link button
`<h${level} id="${hash}"><a href="#${hash}" class="title-link-to-anchor">${headingHtml}</a>`,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you test this modification on MUI X?

This might work, but still create weird HTML with nested <a/> elements

If the title contains a link the code
<a>${headingHtml}</a><a><span><svg>...</svg></span></a>

will return

<a>
	Main title
  <a>Pro component</a>
</a>
<a>
  <span><svg>...</svg></span>
</a>

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, technically, the nested <a> tag is not valid and browsers try to "fix" it, which causes the issue this PR aims to fix.
This PR doesn't fix the nested <a> tag problem but ensures the anchor button works.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding testing, I used this page to verify it works: https://deploy-preview-43598--material-ui.netlify.app/experiments/docs/headers/

@cherniavskii cherniavskii marked this pull request as ready for review September 4, 2024 16:49
@cherniavskii cherniavskii merged commit 2ad38e3 into mui:master Sep 5, 2024
20 of 21 checks passed
@cherniavskii cherniavskii deleted the fix-anchor-for-headers-with-links branch September 5, 2024 12:56
Michael-Hutchinson pushed a commit to Michael-Hutchinson/material-ui that referenced this pull request Sep 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something doesn't work scope: docs-infra Specific to the docs-infra product
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants