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: ensure spatial navigation starts without error without an ErrorD… #8830

Merged
merged 1 commit into from
Aug 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
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');
});