From 4fa9f8b751125efc5f3c5bcc17758a2e5248358e Mon Sep 17 00:00:00 2001 From: cvillasenor Date: Fri, 19 Jul 2024 14:46:21 -0600 Subject: [PATCH 1/5] fix(spatial-navigation): keep navigation going when player has an error --- src/js/spatial-navigation.js | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/src/js/spatial-navigation.js b/src/js/spatial-navigation.js index aa37bbf5d1..682c7c11a8 100644 --- a/src/js/spatial-navigation.js +++ b/src/js/spatial-navigation.js @@ -56,6 +56,10 @@ class SpatialNavigation extends EventTarget { this.player_.on('modalclose', () => { this.refocusComponent(); }); + this.player_.on('error', () => { + // focus vjs close button when error modal appears + this.focus(this.updateFocusableComponents()[0]); + }); this.player_.on('focusin', this.handlePlayerFocus_.bind(this)); this.player_.on('focusout', this.handlePlayerBlur_.bind(this)); this.isListening_ = true; @@ -196,7 +200,7 @@ class SpatialNavigation extends EventTarget { } if (!(event.currentTarget.contains(event.relatedTarget)) && !isChildrenOfPlayer || !nextFocusedElement) { - if (currentComponent.name() === 'CloseButton') { + if (currentComponent && currentComponent.name() === 'CloseButton') { this.refocusComponent(); } else { this.pause(); @@ -307,7 +311,11 @@ class SpatialNavigation extends EventTarget { return null; } - return searchForSuitableChild(component.el()); + if (component.el()) { + return searchForSuitableChild(component.el()); + } + return null; + } /** @@ -464,7 +472,7 @@ class SpatialNavigation extends EventTarget { */ 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); } @@ -492,10 +500,12 @@ class SpatialNavigation extends EventTarget { * @param {Component} component - The component to be focused. */ focus(component) { - if (component.getIsAvailableToBeFocused(component.el())) { - component.focus(); - } else if (this.findSuitableDOMChild(component)) { - this.findSuitableDOMChild(component).focus(); + if (component) { + if (component.getIsAvailableToBeFocused(component.el())) { + component.focus(); + } else if (this.findSuitableDOMChild(component)) { + this.findSuitableDOMChild(component).focus(); + } } } From b047783f648d9c4271d77f063dd825c8204d880b Mon Sep 17 00:00:00 2001 From: cvillasenor Date: Fri, 19 Jul 2024 14:57:53 -0600 Subject: [PATCH 2/5] fix(spatial-navigation): remove unrequired comment --- src/js/spatial-navigation.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/js/spatial-navigation.js b/src/js/spatial-navigation.js index 682c7c11a8..2f3c05ecf8 100644 --- a/src/js/spatial-navigation.js +++ b/src/js/spatial-navigation.js @@ -57,7 +57,6 @@ class SpatialNavigation extends EventTarget { this.refocusComponent(); }); this.player_.on('error', () => { - // focus vjs close button when error modal appears this.focus(this.updateFocusableComponents()[0]); }); this.player_.on('focusin', this.handlePlayerFocus_.bind(this)); From 32066a1154e3829c2c93462b774167ccbd0ecab1 Mon Sep 17 00:00:00 2001 From: cvillasenor Date: Mon, 22 Jul 2024 11:47:02 -0600 Subject: [PATCH 3/5] test(spatial-navigation): verify if start method initializes event listener of error --- test/unit/spatial-navigation.test.js | 1 + 1 file changed, 1 insertion(+) diff --git a/test/unit/spatial-navigation.test.js b/test/unit/spatial-navigation.test.js index 0a28a58bea..00f35d1ee1 100644 --- a/test/unit/spatial-navigation.test.js +++ b/test/unit/spatial-navigation.test.js @@ -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'); From dd1c5c524b92ec4125a63596e0b082d72ec0a4dd Mon Sep 17 00:00:00 2001 From: cvillasenor Date: Mon, 22 Jul 2024 12:40:30 -0600 Subject: [PATCH 4/5] fix(spatial-navigation): update condition in focus component to required an object to execute its logic --- src/js/spatial-navigation.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/js/spatial-navigation.js b/src/js/spatial-navigation.js index 2f3c05ecf8..4f0e38c90b 100644 --- a/src/js/spatial-navigation.js +++ b/src/js/spatial-navigation.js @@ -499,12 +499,14 @@ class SpatialNavigation extends EventTarget { * @param {Component} component - The component to be focused. */ focus(component) { - if (component) { - if (component.getIsAvailableToBeFocused(component.el())) { - component.focus(); - } else if (this.findSuitableDOMChild(component)) { - this.findSuitableDOMChild(component).focus(); - } + if (typeof component !== 'object') { + return; + } + + if (component.getIsAvailableToBeFocused(component.el())) { + component.focus(); + } else if (this.findSuitableDOMChild(component)) { + this.findSuitableDOMChild(component).focus(); } } From e211ac37067c1f73e84bae231ffc592c190b79ae Mon Sep 17 00:00:00 2001 From: cvillasenor Date: Mon, 22 Jul 2024 15:10:47 -0600 Subject: [PATCH 5/5] test(spatial-navigation): verify if on player error updateFocusableComponents is called --- test/unit/spatial-navigation.test.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/unit/spatial-navigation.test.js b/test/unit/spatial-navigation.test.js index 00f35d1ee1..08ade281a8 100644 --- a/test/unit/spatial-navigation.test.js +++ b/test/unit/spatial-navigation.test.js @@ -492,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"'); +});