Skip to content
This repository has been archived by the owner on Feb 19, 2024. It is now read-only.

Commit

Permalink
feat(a11ly): ➜ Pass aria atts and tabindex to link
Browse files Browse the repository at this point in the history
  • Loading branch information
justinwhall committed Jul 6, 2021
1 parent 1c35d6d commit 090e78f
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions packages/styled-components/components/link/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const Link = (props) => {
rel,
target,
theme,
tabIndex,
} = props;
const {
onClick: defaultOnClick,
Expand Down Expand Up @@ -71,15 +72,18 @@ const Link = (props) => {
};

const ariaProps = Object.keys(props).reduce((acc, propName) => {
if (!propName.includes('aria')) {
if (!propName.startsWith('aria')) {
return acc;
}

// Convert aria values to kebab case as camelCase aria key do not work.
const kebabAria = `aria-${propName.replace('aria', '').toLocaleLowerCase()}`;

return {
...acc,
[propName]: props[propName],
[kebabAria]: props[propName],
};
});
}, {});

return (
<LinkWrapper
Expand All @@ -89,6 +93,7 @@ const Link = (props) => {
onClick={handleClick}
rel={rel}
target={target}
tabIndex={tabIndex}
>
{children}
</LinkWrapper>
Expand Down

0 comments on commit 090e78f

Please sign in to comment.