Skip to content

Commit 3fdfe47

Browse files
authored
fix: Avoid creating redundant a11y tree nodes when selecting a block. (#9363)
1 parent f682607 commit 3fdfe47

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

core/renderers/zelos/path_object.ts

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99
import type {BlockSvg} from '../../block_svg.js';
1010
import type {Connection} from '../../connection.js';
11-
import {FocusManager} from '../../focus_manager.js';
1211
import type {BlockStyle} from '../../theme.js';
12+
import * as aria from '../../utils/aria.js';
1313
import * as dom from '../../utils/dom.js';
1414
import {Svg} from '../../utils/svg.js';
1515
import {PathObject as BasePathObject} from '../common/path_object.js';
@@ -90,20 +90,17 @@ export class PathObject extends BasePathObject {
9090
this.setClass_('blocklySelected', enable);
9191
if (enable) {
9292
if (!this.svgPathSelected) {
93-
this.svgPathSelected = this.svgPath.cloneNode(true) as SVGElement;
94-
this.svgPathSelected.classList.add('blocklyPathSelected');
95-
// Ensure focus-specific properties don't overlap with the block's path.
96-
dom.removeClass(
97-
this.svgPathSelected,
98-
FocusManager.ACTIVE_FOCUS_NODE_CSS_CLASS_NAME,
99-
);
100-
dom.removeClass(
101-
this.svgPathSelected,
102-
FocusManager.PASSIVE_FOCUS_NODE_CSS_CLASS_NAME,
93+
this.svgPathSelected = dom.createSvgElement(
94+
Svg.PATH,
95+
{
96+
'class': 'blocklyPath blocklyPathSelected',
97+
'stroke': this.svgPath.getAttribute('stroke') ?? '',
98+
'fill': this.svgPath.getAttribute('fill') ?? '',
99+
'd': this.svgPath.getAttribute('d') ?? '',
100+
'role': aria.Role.PRESENTATION,
101+
},
102+
this.svgRoot,
103103
);
104-
this.svgPathSelected.removeAttribute('tabindex');
105-
this.svgPathSelected.removeAttribute('id');
106-
this.svgRoot.appendChild(this.svgPathSelected);
107104
}
108105
} else {
109106
if (this.svgPathSelected) {

0 commit comments

Comments
 (0)