Skip to content

Commit 1da32c6

Browse files
committed
Add accessibility feature to progress bar
1 parent fdff18d commit 1da32c6

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

dotcom-rendering/src/components/LoopVideoPlayer.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,13 @@ export const LoopVideoPlayer = forwardRef(
8585
}: Props,
8686
ref: React.ForwardedRef<HTMLVideoElement>,
8787
) => {
88+
const loopVideoId = `loop-video-${videoId}`;
89+
8890
return (
8991
<>
9092
{/* eslint-disable-next-line jsx-a11y/media-has-caption -- Captions will be considered later. */}
9193
<video
92-
id={`loop-video-${videoId}`}
94+
id={loopVideoId}
9395
ref={ref}
9496
preload="none"
9597
loop={true}
@@ -138,6 +140,7 @@ export const LoopVideoPlayer = forwardRef(
138140
</button>
139141
)}
140142
<LoopVideoProgressBar
143+
videoId={loopVideoId}
141144
currentTime={currentTime}
142145
duration={ref.current.duration}
143146
/>

dotcom-rendering/src/components/LoopVideoProgressBar.tsx

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,37 @@ const styles = (progressPercentage: number) => css`
1313
`;
1414

1515
type Props = {
16+
videoId: string;
1617
currentTime: number;
1718
duration: number;
1819
};
1920

20-
export const LoopVideoProgressBar = ({ currentTime, duration }: Props) => {
21+
/**
22+
* A progress bar for the loop video component.
23+
*
24+
* Why don't we use the <progress /> element?
25+
* It was not possible to properly style the native progress element in safari.
26+
*/
27+
export const LoopVideoProgressBar = ({
28+
videoId,
29+
currentTime,
30+
duration,
31+
}: Props) => {
2132
if (duration <= 0) return null;
2233

2334
const progressPercentage = (currentTime * 100) / duration;
2435
if (Number.isNaN(progressPercentage)) {
2536
return null;
2637
}
2738

28-
return <div role="progressbar" css={styles(progressPercentage)} />;
39+
return (
40+
<div
41+
role="progressbar"
42+
aria-labelledby={videoId}
43+
aria-valuenow={progressPercentage}
44+
aria-valuemin={0}
45+
aria-valuemax={100}
46+
css={styles(progressPercentage)}
47+
/>
48+
);
2949
};

0 commit comments

Comments
 (0)