Skip to content

feat: Comments ARIA#9832

Merged
mikeharv merged 3 commits intoRaspberryPiFoundation:v13from
mikeharv:comment-aria
May 8, 2026
Merged

feat: Comments ARIA#9832
mikeharv merged 3 commits intoRaspberryPiFoundation:v13from
mikeharv:comment-aria

Conversation

@mikeharv
Copy link
Copy Markdown
Contributor

@mikeharv mikeharv commented May 7, 2026

The basics

The details

Resolves

Fixes #9663

Proposed Changes

This updates ARIA roles and labels for CommentEditor, CommentView, and CommentBarButton (and its subclasses). It introduces parent tracking for CommentEditor and standardizes ARIA roles and labeling across comment views and top bar buttons.

CommentEditor

  • Adds role="textbox" to the textarea
  • Introduces internal parent tracking API:
    • setParent(newParent: BlockSvg | RenderedWorkspaceComment)
    • getParent(): BlockSvg | RenderedWorkspaceComment | undefined
  • Parent is intended to be set by owners - either RenderedWorkspaceComment for workspace comments or by CommentIcon for block comments.

CommentView

  • Sets root element role="button" since enter activates editing.
  • Adds aria-roledescription="Comment" (localized) so that the user gets more than just 'button' context when interacting with the view.
  • Links the view to its editor using aria-labelledby, referencing the editor text area ID.

CommentBarButton (and subclasses)

  • Adds new ARIA API:
    • recomputeAriaContext() to initialize/update ARIA role and label after icon creation.
    • getAriaLabel(): string | null for subclasses to provide contextual labels.
  • Requires explicit call to recomputeAriaContext() after icon initialization
  • Default behavior:
    • Sets role="button" on the icon.
    • Sets aria-label using subclass-provided label or a localized default ("Button").
  • Subclass implementations:
    • CollapseCommentBarButton: dynamically provides "Collapse Comment" / "Expand Comment" based on state.
    • DeleteCommentBarButton: provides "Remove Comment".

Reason for Changes

These changes improve accessibility across comments correct semantic roles and labels for assistive technologies.

Test Coverage

Added unit tests covering:

  • CommentEditor:

    • textarea uses role="textbox"
    • parent object is correctly initialized and accessible via API
  • CommentView:

    • root element has role="button"
    • aria-roledescription is set to "Comment"
    • aria-labelledby correctly references the editor textarea ID
  • CommentBarButton:

    • icons initialize with role="button"
    • buttons correctly compute ARIA labels via getAriaLabel
    • CollapseCommentBarButton updates ARIA label dynamically when toggled
    • DeleteCommentBarButton uses correct static label

@mikeharv mikeharv requested a review from a team as a code owner May 7, 2026 17:13
@mikeharv mikeharv requested a review from gonfunko May 7, 2026 17:13
@github-actions github-actions Bot added the PR: feature Adds a feature label May 7, 2026
Comment thread packages/blockly/tests/mocha/comment_test.js Outdated
Comment thread packages/blockly/tests/mocha/comment_test.js Outdated
@mikeharv mikeharv merged commit 5543e8f into RaspberryPiFoundation:v13 May 8, 2026
4 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