Browse Source

[Beta] Add aria-label and title to permalinks (#4344)

* Add tab index -1

* Improve accessibility
main
Sha Mwe La 3 years ago
committed by GitHub
parent
commit
3d6081f65f
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 10
      beta/src/components/MDX/Heading.tsx

10
beta/src/components/MDX/Heading.tsx

@ -20,6 +20,11 @@ const Heading = forwardRefWithAs<HeadingProps, 'div'>(function Heading(
{as: Comp = 'div', className, children, id, isPageAnchor = true, ...props},
ref
) {
let label = 'Link for this heading';
if (typeof children === 'string') {
label = 'Link for ' + children;
}
return (
<>
<Comp id={id} {...props} ref={ref} className={cn('heading', className)}>
@ -27,11 +32,12 @@ const Heading = forwardRefWithAs<HeadingProps, 'div'>(function Heading(
{isPageAnchor && (
<a
href={`#${id}`}
aria-label={label}
title={label}
className={cn(
anchorClassName,
Comp === 'h1' ? 'hidden' : 'inline-block'
)}
aria-hidden="true">
)}>
<svg
width="1em"
height="1em"

Loading…
Cancel
Save