Skip to content

Commit

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

Add `isHiddenFromScreenReaders` to `Cover`
  • Loading branch information
kasperbirch1 authored Jul 9, 2024
2 parents b6c2a89 + ea110fa commit 2836266
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/stories/Library/cover/Cover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const Cover: FC<CoverProps> = ({
alt,
shadow,
ariaLabel = "Link to the material",
isHiddenFromScreenReaders,
}) => {
const [imageLoaded, setImageLoaded] = useState<boolean | null>(null);

Expand All @@ -28,7 +29,7 @@ const Cover: FC<CoverProps> = ({
),
};

if (coverUrl && alt) {
if (coverUrl) {
// Images inside links must have an non-empty alt text to meet accessibility requirements.
// Only render the cover as a link if we have both an url and a description.
return (
Expand All @@ -38,6 +39,8 @@ const Cover: FC<CoverProps> = ({
aria-label={ariaLabel}
aria-labelledby="cover labelled by"
title="cover title text"
tabIndex={isHiddenFromScreenReaders ? -1 : 0}
aria-hidden={isHiddenFromScreenReaders}
>
<CoverImage
setImageLoaded={() => setImageLoaded(true)}
Expand Down
1 change: 1 addition & 0 deletions src/stories/Library/cover/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ export type CoverProps = {
alt?: string;
shadow?: "small" | "medium";
ariaLabel?: string;
isHiddenFromScreenReaders?: boolean;
};

0 comments on commit 2836266

Please sign in to comment.