Skip to content

Commit

Permalink
fix: ensure spatial navigation starts without error without an ErrorD…
Browse files Browse the repository at this point in the history
…isplay component
  • Loading branch information
mister-ben committed Aug 14, 2024
1 parent 65f8546 commit 114b2f4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 14 deletions.
30 changes: 16 additions & 14 deletions src/js/spatial-navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,25 +59,27 @@ class SpatialNavigation extends EventTarget {
this.player_.on('focusin', this.handlePlayerFocus_.bind(this));
this.player_.on('focusout', this.handlePlayerBlur_.bind(this));
this.isListening_ = true;
this.player_.errorDisplay.on('aftermodalfill', () => {
this.updateFocusableComponents();
if (this.player_.errorDisplay) {
this.player_.errorDisplay.on('aftermodalfill', () => {
this.updateFocusableComponents();

if (this.focusableComponents.length) {
// The modal has focusable components:
if (this.focusableComponents.length) {
// The modal has focusable components:

if (this.focusableComponents.length > 1) {
// The modal has close button + some additional buttons.
// Focusing first additional button:
if (this.focusableComponents.length > 1) {
// The modal has close button + some additional buttons.
// Focusing first additional button:

this.focusableComponents[1].focus();
} else {
// The modal has only close button,
// Focusing it:
this.focusableComponents[1].focus();
} else {
// The modal has only close button,
// Focusing it:

this.focusableComponents[0].focus();
this.focusableComponents[0].focus();
}
}
}
});
});
}
}

/**
Expand Down
8 changes: 8 additions & 0 deletions test/unit/spatial-navigation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -612,3 +612,11 @@ QUnit.test('If component passes the required functions it should be added to foc
assert.strictEqual(this.spatialNav.focusableComponents.length, 1, 'focusableComponents array should have 1 component');
assert.strictEqual(this.spatialNav.focusableComponents[0].name_, 'firstComponent', 'the name of the component in focusableComponents array should be "firstComponent"');
});

QUnit.test('Doesn\'t error if no ErrorDisplay component is present', function(assert) {
this.player.errorDisplay.dispose();
delete this.player.errorDisplay;

this.spatialNav.start();
assert.ok(true, 'started without throwing when errorDisplay not present');
});

0 comments on commit 114b2f4

Please sign in to comment.