Skip to content

feat: Icon ARIA#9805

Merged
mikeharv merged 3 commits intoRaspberryPiFoundation:v13from
mikeharv:icon-aria
May 4, 2026
Merged

feat: Icon ARIA#9805
mikeharv merged 3 commits intoRaspberryPiFoundation:v13from
mikeharv:icon-aria

Conversation

@mikeharv
Copy link
Copy Markdown
Contributor

@mikeharv mikeharv commented May 1, 2026

The basics

The details

Resolves

Fixes #9662

Proposed Changes

Updates Icon and its subclasses with the following API changes:

/**
 * Recomputes the ARIA label and role for this icon. This is automatically called
 * during initialization, but implementations may find it useful to call this if
 * the icon's label should be changed.
 */
protected recomputeAriaContext()

/**
 * Returns the ARIA label to use for this icon (defaults to null). Note that this
 * method will only be called during initialization by default, so dynamic changes
 * to the icon's ARIA label need to be applied by calling recomputeAriaContext.
 *
 * @returns The ARIA label to use for this icon, or null to use a default.
 */
protected getAriaLabel(): string | null

This follows a similar pattern to Bubbles including defaulting the label to 'Icon' if no override is provided. By default, Icons are given the role button as it best fits their interactive nature since it's expected that Icons are always clickable. Developers are thus expected to use non-clickable FieldImages when they want to include non-clickable graphics as part of a block.

Icons are also responsible for configuring their corresponding Bubbles to have correct ARIA labels (with translation support). This is done by providing an AriaLabelProvider string or function to the Bubble. This is done because Bubble and its subtypes do not have any particular awareness of the context in which they are being used.

Icons for Mutators, Warnings, and Comments have a new getAriaLabel override that returns a localized message pertaining to opening its bubble or closing it. The bubble itself will be labeled either as 'Block editor workspace' (mutator) or the full bubble text preceded by 'Warning: '/'Comment: '.

In order to ensure that labels for comment bubbles are updated, a change listener was added to TextInputBubble. Note that read-only workspaces use TextBubble, which does need to have a similar mechanism due to users not being able to type. Warnings are also effectively read-only.

Reason for Changes

This gives built-in bubble owners (mutators, warnings, and comments) correct dynamically updated ARIA labels and roles for their icons and bubbles. This will also make it possible for developers to do the same for their own Icon implementations.

Test Coverage

A new test suite was added for Icon which tests roles and labels for generic icons. For mutators, warnings, and comments, existing suites were updated check label providers, expected roles for icons and bubbles, and dynamic updates from toggling the bubble visibility and updating comment text.

Documentation

Additional Information

@mikeharv mikeharv requested a review from a team as a code owner May 1, 2026 19:00
@mikeharv mikeharv requested a review from gonfunko May 1, 2026 19:00
@github-actions github-actions Bot added the PR: feature Adds a feature label May 1, 2026
Comment thread packages/blockly/core/bubbles/textinput_bubble.ts Outdated
Comment thread packages/blockly/core/icons/comment_icon.ts Outdated
Comment thread packages/blockly/core/icons/icon.ts Outdated
Comment thread packages/blockly/tests/mocha/block_test.js Outdated
Comment thread packages/blockly/tests/mocha/comment_test.js Outdated
Comment thread packages/blockly/tests/mocha/mutator_test.js Outdated
@mikeharv mikeharv requested a review from gonfunko May 4, 2026 12:58
Comment thread packages/blockly/tests/mocha/comment_test.js Outdated
Comment thread packages/blockly/core/bubbles/textinput_bubble.ts Outdated
@mikeharv mikeharv requested a review from gonfunko May 4, 2026 15:19
@mikeharv mikeharv merged commit 4bfbd35 into RaspberryPiFoundation:v13 May 4, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

PR: feature Adds a feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants