Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(player): refactor 'searchForTrackSelect' to be handled in the spatial navigation. #21

Merged
merged 2 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -53,33 +53,6 @@ class CaptionSettingsMenuItem extends TextTrackMenuItem {
*/
handleClick(event) {
this.player().getChild('textTrackSettings').open();

const spatialNavigation = this.player_.spatialNavigation;
const isSpatialNavListening = spatialNavigation && spatialNavigation.isListening_ && !spatialNavigation.isPaused_;

if (isSpatialNavListening) {
this.searchForTrackSelect();
}
}

/**
* This gets called by 'handleClick' if 'spatialNavigation' is enabled.
* Searches for the first 'TextTrackSelect' inside of modal to focus.
*/
searchForTrackSelect() {
const spatialNavigation = this.player().spatialNavigation;
let componentToFocus = null;

for (const component of (spatialNavigation.updateFocusableComponents())) {
if (component.constructor.name === 'TextTrackSelect') {
componentToFocus = component;
break;
}
}

if (componentToFocus) {
spatialNavigation.focus(componentToFocus);
}
}

/**
Expand Down
21 changes: 21 additions & 0 deletions src/js/spatial-navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,11 @@ class SpatialNavigation extends EventTarget {

if (nextFocusedElement) {
isChildrenOfPlayer = Boolean(nextFocusedElement.closest('.video-js'));

// If nextFocusedElement is the 'TextTrackSettings' component
if (nextFocusedElement.classList.contains('vjs-text-track-settings') && !this.isPaused_) {
this.searchForTrackSelect();
}
}

if (!(event.currentTarget.contains(event.relatedTarget)) && !isChildrenOfPlayer || !nextFocusedElement) {
Expand All @@ -184,6 +189,7 @@ class SpatialNavigation extends EventTarget {
this.pause();

if (currentComponent && currentComponent.el()) {
// Store last focused component
this.lastFocusedComponent_ = currentComponent;
}
}
Expand Down Expand Up @@ -517,6 +523,21 @@ class SpatialNavigation extends EventTarget {

return distance;
}

/**
* This gets called by 'handleClick' if 'spatialNavigation' is enabled.
* Searches for the first 'TextTrackSelect' inside of modal to focus.
*/
searchForTrackSelect() {
const spatialNavigation = this;

for (const component of (spatialNavigation.updateFocusableComponents())) {
if (component.constructor.name === 'TextTrackSelect') {
spatialNavigation.focus(component);
break;
}
}
}
}

export default SpatialNavigation;
Loading