Skip to content

Commit

Permalink
Find video by id instead of by tagname
Browse files Browse the repository at this point in the history
Defaults to find the first video on the dom if no videoId prop is passed
  • Loading branch information
yisusans committed Nov 9, 2017
1 parent 91bc945 commit ce8e43e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
10 changes: 7 additions & 3 deletions src/video/video.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ export default (
BaseComponent,
mapStateToProps = defaultMapStateToProps,
mapVideoElToProps = defaultMapVideoElToProps,
mergeProps = defaultMergeProps
mergeProps = defaultMergeProps,
videoId
) => class Video extends Component {
constructor(props) {
super(props);
Expand Down Expand Up @@ -95,14 +96,17 @@ export default (
this.unbindEvents();
}

// Stop `this.el` from being null briefly on every render,
// Stop `this.el` from being null briefly on every rendxwxer,
// see: https://github.com/mderrick/react-html5video/pull/65
setRef(el) {
this.el = findDOMNode(el);
}

componentDidMount() {
this.videoEl = this.el.getElementsByTagName('video')[0];
const videoEls = this.el.getElementsByTagName('video');
this.videoEl = videoId
? videoEls.namedItem(videoId)
: videoEls[0];
this.bindEventsToUpdateState();
}

Expand Down
25 changes: 22 additions & 3 deletions src/video/video.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ const TestVideo = ({ video, ...restProps }) => {
<video {...restProps}>
<source src="1" />
</video>
<video
id="video2"
{...restProps}
>
<source src="2" />
</video>
<TestControl {...video} />
</div>
);
Expand Down Expand Up @@ -228,7 +234,20 @@ describe('video', () => {
expect(component.find(TestVideo).prop('duplicateKey')).toBe('mapVideoElToProps');
});
});
});



describe('when passing in a video id as the fourth argument to the HOC', () => {
const videoEl = { id: 'video2' };
beforeEach(() => {
component = shallow(
<Component />
);

// Emulate videoEl being present
// e.g. componentDidMount
component.instance().videoEl = videoEl;
});
it('should find the video by id', () => {
expect(videoEl.id).toEqual('video2');
});
});
});

0 comments on commit ce8e43e

Please sign in to comment.