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

fix(spatial-navigation): keep navigation going when player has an error #8805

Merged
merged 5 commits into from
Jul 22, 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
17 changes: 14 additions & 3 deletions src/js/spatial-navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@
this.player_.on('modalclose', () => {
this.refocusComponent();
});
this.player_.on('error', () => {
this.focus(this.updateFocusableComponents()[0]);
});
this.player_.on('focusin', this.handlePlayerFocus_.bind(this));
this.player_.on('focusout', this.handlePlayerBlur_.bind(this));
this.isListening_ = true;
Expand Down Expand Up @@ -196,7 +199,7 @@
}

if (!(event.currentTarget.contains(event.relatedTarget)) && !isChildrenOfPlayer || !nextFocusedElement) {
if (currentComponent.name() === 'CloseButton') {
if (currentComponent && currentComponent.name() === 'CloseButton') {
this.refocusComponent();
} else {
this.pause();
Expand Down Expand Up @@ -307,7 +310,11 @@
return null;
}

return searchForSuitableChild(component.el());
if (component.el()) {
return searchForSuitableChild(component.el());
}
return null;

Check warning on line 316 in src/js/spatial-navigation.js

View check run for this annotation

Codecov / codecov/patch

src/js/spatial-navigation.js#L316

Added line #L316 was not covered by tests

}

/**
Expand Down Expand Up @@ -464,7 +471,7 @@
*/
refocusComponent() {
if (this.lastFocusedComponent_) {
// If use is not active, set it to active.
// If user is not active, set it to active.
if (!this.player_.userActive()) {
this.player_.userActive(true);
}
Expand Down Expand Up @@ -492,6 +499,10 @@
* @param {Component} component - The component to be focused.
*/
focus(component) {
if (typeof component !== 'object') {
return;
}

if (component.getIsAvailableToBeFocused(component.el())) {
component.focus();
} else if (this.findSuitableDOMChild(component)) {
Expand Down
11 changes: 11 additions & 0 deletions test/unit/spatial-navigation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ QUnit.test('start method initializes event listeners', function(assert) {
assert.ok(onSpy.calledWith('loadedmetadata'), 'loadedmetadata event listener added');
assert.ok(onSpy.calledWith('modalKeydown'), 'modalKeydown event listener added');
assert.ok(onSpy.calledWith('modalclose'), 'modalclose event listener added');
assert.ok(onSpy.calledWith('error'), 'error event listener added');

// Additionally, check if isListening_ flag is set
assert.ok(this.spatialNav.isListening_, 'isListening_ flag is set');
Expand Down Expand Up @@ -491,3 +492,13 @@ QUnit.test('should call `searchForTrackSelect()` if spatial navigation is enable

assert.ok(trackSelectSpy.calledOnce);
});

QUnit.test('error on player calls updateFocusableComponents', function(assert) {
const updateFocusableComponentsSpy = sinon.spy(this.spatialNav, 'updateFocusableComponents');

this.spatialNav.start();

this.player.error('Error 1');

assert.ok(updateFocusableComponentsSpy.calledOnce, 'on error event spatial navigation should call "updateFocusableComponents"');
});