fix: Avoid creating redundant a11y tree nodes when selecting a block. (#9363)

This commit is contained in:
Aaron Dodson
2025-09-15 11:40:07 -07:00
committed by GitHub
parent f682607a6c
commit 3fdfe47970

View File

@@ -8,8 +8,8 @@
import type {BlockSvg} from '../../block_svg.js';
import type {Connection} from '../../connection.js';
import {FocusManager} from '../../focus_manager.js';
import type {BlockStyle} from '../../theme.js';
import * as aria from '../../utils/aria.js';
import * as dom from '../../utils/dom.js';
import {Svg} from '../../utils/svg.js';
import {PathObject as BasePathObject} from '../common/path_object.js';
@@ -90,20 +90,17 @@ export class PathObject extends BasePathObject {
this.setClass_('blocklySelected', enable);
if (enable) {
if (!this.svgPathSelected) {
this.svgPathSelected = this.svgPath.cloneNode(true) as SVGElement;
this.svgPathSelected.classList.add('blocklyPathSelected');
// Ensure focus-specific properties don't overlap with the block's path.
dom.removeClass(
this.svgPathSelected,
FocusManager.ACTIVE_FOCUS_NODE_CSS_CLASS_NAME,
this.svgPathSelected = dom.createSvgElement(
Svg.PATH,
{
'class': 'blocklyPath blocklyPathSelected',
'stroke': this.svgPath.getAttribute('stroke') ?? '',
'fill': this.svgPath.getAttribute('fill') ?? '',
'd': this.svgPath.getAttribute('d') ?? '',
'role': aria.Role.PRESENTATION,
},
this.svgRoot,
);
dom.removeClass(
this.svgPathSelected,
FocusManager.PASSIVE_FOCUS_NODE_CSS_CLASS_NAME,
);
this.svgPathSelected.removeAttribute('tabindex');
this.svgPathSelected.removeAttribute('id');
this.svgRoot.appendChild(this.svgPathSelected);
}
} else {
if (this.svgPathSelected) {