Skip to content

fix: Add default aria role to svg and group elements#9697

Merged
lizschwab merged 2 commits intoRaspberryPiFoundation:v13from
lizschwab:rpf-9664
Apr 10, 2026
Merged

fix: Add default aria role to svg and group elements#9697
lizschwab merged 2 commits intoRaspberryPiFoundation:v13from
lizschwab:rpf-9664

Conversation

@lizschwab
Copy link
Copy Markdown
Contributor

The basics

The details

Resolves

Fixes #9664

Proposed Changes

Adds role=generic to svg elements of type g and type svg

Reason for Changes

This change ensures that browsers and screen readers do not attempt to associate additional semantic information with these elements.

Test Coverage

Added unit tests which cover the following scenarios:

  • Creating svg elements with the name or nameTag 'g' or 'svg' results in the generic role being added
  • Passing in a specific role will override the default 'generic' role
  • Other element types are not affected by these changes

@lizschwab lizschwab requested a review from a team as a code owner April 10, 2026 18:54
@lizschwab lizschwab requested a review from gonfunko April 10, 2026 18:54
@github-actions github-actions bot added the PR: fix Fixes a bug label Apr 10, 2026
Copy link
Copy Markdown
Contributor

@gonfunko gonfunko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a couple minor nits but looks good, thanks!

* For svg and group (g) elements, we set the role to generic so that they are ignored by assistive technologies.
*/
if (
name === 'svg' ||
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than string literals, it might be preferable to use Svg.G.tagName and Svg.SVG.tagName (from utils/svg.ts)

});
test('svg elements of type svg have the generic role by default', function () {
const svgSvg = Blockly.utils.dom.createSvgElement(
Blockly.utils.Svg.G,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be Blockly.utils.Svg.SVG I think?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, thanks for catching that!


import type {Svg} from './svg.js';
import * as aria from './aria.js';
import {Svg} from './svg.js';
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In order to use Svg as a value below I needed to change the import statement. This does not appear to affect anything, but I wanted to highlight it as I'm unsure of the reasons we were previously importing it as a type.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally we just import the type alone if it's being used strictly for TS typings, e.g. never instantiated/having any fields accessed. It's fine to import the full thing when we are actually using it though.

* For svg and group (g) elements, we set the role to generic so that they are ignored by assistive technologies.
*/
if (
name === Svg.SVG.toString() ||
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Svg.SVG.tagName is private, but toString() returns the tagName.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah good point, but yes this is fine, thanks!

@lizschwab lizschwab requested a review from gonfunko April 10, 2026 21:23

import type {Svg} from './svg.js';
import * as aria from './aria.js';
import {Svg} from './svg.js';
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally we just import the type alone if it's being used strictly for TS typings, e.g. never instantiated/having any fields accessed. It's fine to import the full thing when we are actually using it though.

* For svg and group (g) elements, we set the role to generic so that they are ignored by assistive technologies.
*/
if (
name === Svg.SVG.toString() ||
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah good point, but yes this is fine, thanks!

@lizschwab lizschwab merged commit a61222f into RaspberryPiFoundation:v13 Apr 10, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

PR: fix Fixes a bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants