Skip to content

Media: Refresh attachment tile aria-label when model data loads - #13053

Open
sornapudisuresh wants to merge 1 commit into
WordPress:trunkfrom
sornapudisuresh:fix/65852-media-attachment-aria-label
Open

Media: Refresh attachment tile aria-label when model data loads#13053
sornapudisuresh wants to merge 1 commit into
WordPress:trunkfrom
sornapudisuresh:fix/65852-media-attachment-aria-label

Conversation

@sornapudisuresh

Copy link
Copy Markdown

Media Library grid tiles can keep a stale aria-label (uploading… / (no title)) when the view is created for an id-only attachment model that is still fetching. The visible CSS label overlay (added in 7.0) makes that staleness obvious to everyone, not only screen reader users.

Problem

wp.media.view.Attachment computes aria-label only in attributes(), and Backbone evaluates that once during _ensureElement(). Core (and Gutenberg) often create tiles via Attachment.get( id ) + fetch(), so the label is computed from empty model data and never updates when the model later receives a title — even though render() re-runs on model change.

This is distinct from #65438 / [62892], which only changes which fallback string is used for a titleless model.

Fix

  • Factor the label computation into getAriaLabel().
  • Re-apply aria-label at the end of render() once the model has data.
  • Skip subclasses that reset attributes (e.g. Attachment.Details, see #47458) so we do not add inappropriate attributes there.
  • Leave aria-checked alone so selection state from updateSelect() is not clobbered.

Testing instructions

  1. Use the Playground blueprint from the Trac ticket, or locally:
    • Create a post with a titled featured image.
    • Reload the post edit screen and open the Featured image modal.
  2. Confirm the selected tile label updates to the attachment title (not stuck on uploading… / (no title)).
  3. Confirm untitled tiles still show (no title), and in-progress uploads still show uploading….
  4. Confirm Attachment Details (sidebar) is unchanged (no checkbox/aria-label attributes added).

Trac ticket: https://core.trac.wordpress.org/ticket/65852

Use of AI Tools

AI assistance: Yes
Tool(s): Cursor
Model(s): Cursor Grok 4.5
Used for: Implementation assistance following the approach suggested on the Trac ticket. Changes were reviewed against the codebase and existing Attachment.Details attribute reset pattern.


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

Backbone only evaluates attributes() when the element is created, so tiles
built for id-only models kept a stale uploading/(no title) label after fetch.
Re-apply the accessible name in render() so the label catches up.
@github-actions

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props sureshsornapudi09.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@github-actions

Copy link
Copy Markdown

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant