From 2250f45b89deaec0adea577184e5b20f7caaaf1b Mon Sep 17 00:00:00 2001 From: Taya Leutina Date: Tue, 23 Sep 2025 15:20:16 +0300 Subject: [PATCH 1/3] fix(Media): support boolean loop for default video --- src/blocks/Media/__stories__/data.json | 4 +- src/components/DefaultVideo/DefaultVideo.tsx | 40 +++++++++++--------- 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/src/blocks/Media/__stories__/data.json b/src/blocks/Media/__stories__/data.json index 89db01b63..6efb5f49b 100644 --- a/src/blocks/Media/__stories__/data.json +++ b/src/blocks/Media/__stories__/data.json @@ -93,9 +93,7 @@ "/story-assets/video_8-12_white.mp4", "/story-assets/video_8-12_white.png" ], - "loop": { - "start": 0 - }, + "loop": true, "ariaLabel": "Video accessible name example" } }, diff --git a/src/components/DefaultVideo/DefaultVideo.tsx b/src/components/DefaultVideo/DefaultVideo.tsx index 7145045ee..8fe8e4565 100644 --- a/src/components/DefaultVideo/DefaultVideo.tsx +++ b/src/components/DefaultVideo/DefaultVideo.tsx @@ -21,7 +21,13 @@ interface DefaultVideoProps { export const DefaultVideo = React.forwardRef( (props, ref) => { const {video, qa, customBarControlsClassName} = props; - const {controls, customControlsOptions, muted: initiallyMuted = true, onVideoEnd} = video; + const { + controls, + customControlsOptions, + muted: initiallyMuted = true, + onVideoEnd, + loop, + } = video; const { muteButtonShown, positioning, @@ -45,22 +51,6 @@ export const DefaultVideo = React.forwardRef { - const videoElement = videoRef.current; - if (!videoElement || !onVideoEnd) { - return undefined; - } - - const handleVideoEnd = () => { - onVideoEnd?.(); - }; - - videoElement.addEventListener('ended', handleVideoEnd); - return () => { - videoElement.removeEventListener('ended', handleVideoEnd); - }; - }, [videoRef, onVideoEnd]); - // to guarantee setting a muted attribute in HTML. https://github.com/facebook/react/issues/10389 React.useEffect(() => { const videoElement = videoRef.current; @@ -81,6 +71,7 @@ export const DefaultVideo = React.forwardRef { setIsMuted((value) => !value); }, []); @@ -91,6 +82,20 @@ export const DefaultVideo = React.forwardRef { + const videoElement = videoRef.current; + if (!videoElement) { + return; + } + + if (loop) { + videoElement.currentTime = 0; + videoElement.play(); + } + + onVideoEnd?.(); + }, [loop, onVideoEnd]); + return (