Skip to content

Commit db2a284

Browse files
authored
Merge pull request #29 from vev-design/e-233-video-black-bar-shows-on-initial-load
Set styles in css instead of injecting with useEffect
2 parents 55b7d18 + b28728a commit db2a284

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

video/src/Video.module.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
width: 100%;
1111
height: 100%;
1212
filter: none;
13+
object-fit: contain;
14+
&.fill {
15+
object-fit: cover;
16+
}
1317
}
1418

1519
.ie .video {

video/src/Video.tsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -181,11 +181,9 @@ const Video = ({
181181
if (isIE()) attributes.className = 'ie';
182182
if (autoplay) attributes.autoPlay = true;
183183

184-
useEffect(() => {
185-
const videoEl = videoRef.current;
186-
if (!videoEl) return;
187-
videoEl.style.objectFit = fill ? 'cover' : 'contain';
188-
}, [fill, videoRef.current]);
184+
let videoCl = styles.video;
185+
if (fill) videoCl += ' ' + styles.fill;
186+
189187

190188
return (
191189
<div className={styles.wrapper}>
@@ -200,7 +198,7 @@ const Video = ({
200198
aria-label={video?.name || ''}
201199
playsInline
202200
disableRemotePlayback
203-
className={styles.video}
201+
className={videoCl}
204202
poster={thumbnail && thumbnail.url ? thumbnail.url : video && video.thumbnail}
205203
preload={preload}
206204
{...attributes}

0 commit comments

Comments
 (0)