Skip to content

Commit

Permalink
[docs] Expose heading links in a11y tree (#25861)
Browse files Browse the repository at this point in the history
  • Loading branch information
eps1lon authored Apr 22, 2021
1 parent a4d8c4f commit 0181186
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
8 changes: 4 additions & 4 deletions docs/src/modules/components/ApiPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,13 @@ function getTranslatedHeader(t, header) {
function Heading(props) {
const { hash, level: Level = 'h2' } = props;
const t = useTranslate();
const headingId = `heading-${hash}`;

return (
<Level>
{/* eslint-disable-next-line jsx-a11y/anchor-is-valid, jsx-a11y/anchor-has-content */}
<a className="anchor-link" id={hash} />
<Level id={headingId}>
<span className="anchor-link" id={hash} />
{getTranslatedHeader(t, hash)}
<a className="anchor-link-style" aria-hidden="true" aria-label="anchor" href={`#${hash}`}>
<a aria-labelledby={headingId} className="anchor-link-style" href={`#${hash}`} tabIndex={-1}>
<svg>
<use xlinkHref="#anchor-link-icon" />
</svg>
Expand Down
7 changes: 4 additions & 3 deletions docs/src/modules/utils/parseMarkdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,12 +187,13 @@ export function createRender(context) {
hash,
});
}
const headingId = `heading-${hash}`;

return [
`<h${level}>`,
`<a class="anchor-link" id="${hash}"></a>`,
`<h${level} id="${headingId}">`,
`<span class="anchor-link" id="${hash}"></span>`,
headingHtml,
`<a class="anchor-link-style" aria-hidden="true" href="#${hash}">`,
`<a aria-labelledby="${headingId}" class="anchor-link-style" href="#${hash}" tabindex="-1">`,
'<svg><use xlink:href="#anchor-link-icon" /></svg>',
'</a>',
`</h${level}>`,
Expand Down

0 comments on commit 0181186

Please sign in to comment.