Skip to content

Commit

Permalink
Merge pull request #1313 from danskernesdigitalebibliotek/DDFFORM-719…
Browse files Browse the repository at this point in the history
…-cover-accessibility

Improve `Cover` accessibility by adding `isHiddenFromScreenReaders` attribute to `Link` component - Ddfform 719
  • Loading branch information
kasperbirch1 authored Jul 9, 2024
2 parents 77f4742 + a86a334 commit 814e169
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/components/atoms/links/Link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export interface LinkProps {
dataCy?: string;
ariaLabelledBy?: string;
stopPropagation?: boolean;
isHiddenFromScreenReaders?: boolean;
}

const Link: React.FC<LinkProps> = ({
Expand All @@ -22,7 +23,8 @@ const Link: React.FC<LinkProps> = ({
trackClick,
dataCy,
ariaLabelledBy,
stopPropagation = false
stopPropagation = false,
isHiddenFromScreenReaders
}) => {
const handleClick = getLinkHandler({
type: "click",
Expand Down Expand Up @@ -51,6 +53,8 @@ const Link: React.FC<LinkProps> = ({
onClick={handleClick}
onKeyUp={handleKeyUp}
aria-labelledby={ariaLabelledBy}
tabIndex={isHiddenFromScreenReaders ? -1 : 0}
aria-hidden={isHiddenFromScreenReaders}
>
{children}
</a>
Expand Down
5 changes: 4 additions & 1 deletion src/components/atoms/links/LinkNoStyle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export interface LinkNoStyleProps {
trackClick?: () => Promise<unknown>;
dataCy?: string;
ariaLabelledBy?: string;
isHiddenFromScreenReaders?: boolean;
}

const LinkNoStyle: React.FC<LinkNoStyleProps> = ({
Expand All @@ -18,7 +19,8 @@ const LinkNoStyle: React.FC<LinkNoStyleProps> = ({
className,
trackClick,
dataCy = "link-no-style",
ariaLabelledBy
ariaLabelledBy,
isHiddenFromScreenReaders
}) => {
return (
<Link
Expand All @@ -28,6 +30,7 @@ const LinkNoStyle: React.FC<LinkNoStyleProps> = ({
trackClick={trackClick}
dataCy={dataCy}
ariaLabelledBy={ariaLabelledBy}
isHiddenFromScreenReaders={isHiddenFromScreenReaders}
>
{children}
</Link>
Expand Down
1 change: 1 addition & 0 deletions src/components/cover/cover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ export const Cover = ({
className={classes.wrapper}
url={url}
ariaLabelledBy={linkAriaLabelledBy}
isHiddenFromScreenReaders={!alt}
>
{coverSrc && (
<CoverImage
Expand Down

0 comments on commit 814e169

Please sign in to comment.