Skip to content
Open
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
9 changes: 7 additions & 2 deletions packages/blockly/core/keyboard_navigation_controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
* SPDX-License-Identifier: Apache-2.0
*/

import {getMainWorkspace} from './common.js';
import type {WorkspaceSvg} from './workspace_svg.js';

/**
* The KeyboardNavigationController handles coordinating Blockly-wide
* keyboard navigation behavior, such as enabling/disabling full
Expand Down Expand Up @@ -69,10 +72,12 @@ export class KeyboardNavigationController {

/** Adds or removes the css class that indicates keyboard navigation is active. */
private updateActiveVisualization() {
const root = (getMainWorkspace() as WorkspaceSvg).getInjectionDiv()
.parentElement;
if (this.isActive) {
document.body.classList.add(this.activeClassName);
root?.classList.add(this.activeClassName);
} else {
document.body.classList.remove(this.activeClassName);
root?.classList.remove(this.activeClassName);
}
}
}
Expand Down
7 changes: 4 additions & 3 deletions packages/blockly/core/rendered_connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -719,9 +719,10 @@ export class RenderedConnection
private findHighlightSvg(): SVGPathElement | null {
// This cast is valid as TypeScript's definition is wrong. See:
// https://github.com/microsoft/TypeScript/issues/60996.
return document.getElementById(this.id) as
| unknown
| null as SVGPathElement | null;
const root = this.getSourceBlock().getSvgRoot().getRootNode() as
| ShadowRoot
| HTMLDocument;
return root.getElementById(this.id) as SVGPathElement | null;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
suite('Keyboard Navigation Controller', function () {
setup(function () {
sharedTestSetup.call(this);
this.workspace = Blockly.inject('blocklyDiv');
Blockly.keyboardNavigationController.setIsActive(false);
});

Expand All @@ -24,14 +25,18 @@ suite('Keyboard Navigation Controller', function () {
test('Setting active keyboard navigation adds css class', function () {
Blockly.keyboardNavigationController.setIsActive(true);
assert.isTrue(
document.body.classList.contains('blocklyKeyboardNavigation'),
Blockly.getMainWorkspace()
.getInjectionDiv()
.parentElement.classList.contains('blocklyKeyboardNavigation'),
);
});

test('Disabling active keyboard navigation removes css class', function () {
Blockly.keyboardNavigationController.setIsActive(false);
assert.isFalse(
document.body.classList.contains('blocklyKeyboardNavigation'),
Blockly.getMainWorkspace()
.getInjectionDiv()
.parentElement.classList.contains('blocklyKeyboardNavigation'),
);
});
});
Loading