Skip to content

Commit 5b2d4ce

Browse files
nirmaozNir Maoz
authored andcommitted
Add support for innerRef to the Video component
1 parent 28ae461 commit 5b2d4ce

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

src/components/Video/Video.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class Video extends CloudinaryComponent {
1818
}
1919

2020
render() {
21-
let {publicId, poster, sourceTypes, fallback, sourceTransformation: sourceTransformations, ...options} = Object.assign({},
21+
let {publicId, poster, sourceTypes, fallback, sourceTransformation: sourceTransformations, innerRef, ...options} = Object.assign({},
2222
this.getContext(),
2323
this.props);
2424
sourceTransformations = sourceTransformations || {};
@@ -53,7 +53,7 @@ class Video extends CloudinaryComponent {
5353
}
5454

5555
return (
56-
<video {...tagAttributes}>
56+
<video ref={innerRef} {...tagAttributes}>
5757
{sources}
5858
{fallback}
5959
{this.props.children}

test/VideoTest.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22
import chai, { expect } from 'chai';
3-
import {shallow} from 'enzyme';
3+
import {shallow, mount} from 'enzyme';
44
import Video from '../src/components/Video';
55
import Transformation from '../src/components/Transformation';
66

@@ -85,4 +85,26 @@ describe('Video', () => {
8585
);
8686
expect(tag.type()).to.equal("video");
8787
});
88+
89+
it('Should support forwarding innerRef to underlying video element', function () {
90+
let myRef = React.createRef();
91+
92+
let tag = mount(
93+
<Video
94+
innerRef={myRef}
95+
cloudName='demo'
96+
sourceTypes='webm'
97+
publicId='dog'
98+
sourceTransformation={{
99+
webm: {overlay: 'text:verdana_30:webm!'}
100+
}}
101+
/>
102+
);
103+
104+
const video = myRef.current;
105+
106+
expect(tag.find('video').prop('src')).to.endWith('/l_text:verdana_30:webm!/dog.webm');
107+
expect(video.src).to.endWith('/l_text:verdana_30:webm!/dog.webm');
108+
['play','pause','canPlayType','addTextTrack'].forEach(func=>expect(video[func]).to.be.a('function'));
109+
});
88110
});

0 commit comments

Comments
 (0)