Skip to content

Commit b68f211

Browse files
author
yisusans
committed
Find video by id instead of by tagname
Defaults to find the first video on the dom if no videoId prop is passed
1 parent 91bc945 commit b68f211

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

src/video/video.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ export default (
3131
BaseComponent,
3232
mapStateToProps = defaultMapStateToProps,
3333
mapVideoElToProps = defaultMapVideoElToProps,
34-
mergeProps = defaultMergeProps
34+
mergeProps = defaultMergeProps,
35+
videoId
3536
) => class Video extends Component {
3637
constructor(props) {
3738
super(props);
@@ -102,7 +103,10 @@ export default (
102103
}
103104

104105
componentDidMount() {
105-
this.videoEl = this.el.getElementsByTagName('video')[0];
106+
const videoEls = this.el.getElementsByTagName('video');
107+
this.videoEl = videoId
108+
? videoEls.namedItem(videoId)
109+
: videoEls[0];
106110
this.bindEventsToUpdateState();
107111
}
108112

src/video/video.test.js

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ const TestVideo = ({ video, ...restProps }) => {
2020
<video {...restProps}>
2121
<source src="1" />
2222
</video>
23+
<video
24+
id="video2"
25+
{...restProps}
26+
>
27+
<source src="2" />
28+
</video>
2329
<TestControl {...video} />
2430
</div>
2531
);
@@ -228,7 +234,20 @@ describe('video', () => {
228234
expect(component.find(TestVideo).prop('duplicateKey')).toBe('mapVideoElToProps');
229235
});
230236
});
231-
});
232-
233-
234237

238+
describe('when passing in a video id as the fourth argument to the HOC', () => {
239+
const videoEl = { id: 'video2' };
240+
beforeEach(() => {
241+
component = shallow(
242+
<Component />
243+
);
244+
245+
// Emulate videoEl being present
246+
// e.g. componentDidMount
247+
component.instance().videoEl = videoEl;
248+
});
249+
it('should find the video by id', () => {
250+
expect(videoEl.id).toEqual('video2');
251+
});
252+
});
253+
});

0 commit comments

Comments
 (0)