fix: Fix styling and focusing of connections in shadow DOM (#9952)

This commit is contained in:
Aaron Dodson
2026-06-10 19:22:56 +01:00
committed by GitHub
parent b69c38d6cc
commit 00882a8b22
3 changed files with 18 additions and 7 deletions
@@ -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
@@ -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);
}
}
}
+4 -3
View File
@@ -720,9 +720,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;
}
}
@@ -13,6 +13,7 @@ import {
suite('Keyboard Navigation Controller', function () {
setup(function () {
sharedTestSetup.call(this);
this.workspace = Blockly.inject('blocklyDiv');
Blockly.keyboardNavigationController.setIsActive(false);
});
@@ -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'),
);
});
});