Skip to content

Conversation

caseyisonit
Copy link
Contributor

@caseyisonit caseyisonit commented Sep 15, 2025

Description

This PR resolves a small accessibility bug related to caching aria labels when pending state controllers are used on components. The controller will now cache aria labels before updating as well as re-cache if there was a change to the aria label since the last pending state. This also solves a bug where the aria label was being removed entirely, even if an aria label was present before pending.

Motivation and context

correctly toggles aria-labels based on pending state

Related issue(s)

  • fixes [5620]

Screenshots (if appropriate)


Author's checklist

  • I have read the CONTRIBUTING and PULL_REQUESTS documents.
  • I have reviewed at the Accessibility Practices for this feature, see: Aria Practices
  • I have added automated tests to cover my changes.
  • I have included a well-written changeset if my change needs to be published.
  • I have included updated documentation if my change required it.

Reviewer's checklist

  • Includes a Github Issue with appropriate flag or Jira ticket number without a link
  • Includes thoughtfully written changeset if changes suggested include patch, minor, or major features
  • Automated tests cover all use cases and follow best practices for writing
  • Validated on all supported browsers
  • All VRTs are approved before the author can update Golden Hash

Manual review test cases

  • Descriptive Test Statement

    1. Go here
    2. Do this action
    3. Expect this result
  • Descriptive Test Statement

    1. Go here
    2. Do this action
    3. Expect this result

Device review

  • Did it pass in Desktop?
  • Did it pass in (emulated) Mobile?
  • Did it pass in (emulated) iPad?

Copy link

changeset-bot bot commented Sep 15, 2025

⚠️ No Changeset found

Latest commit: ba8e5c9

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Contributor

📚 Branch Preview

🔍 Visual Regression Test Results

When a visual regression test fails (or has previously failed while working on this branch), its results can be found in the following URLs:

Deployed to Azure Blob Storage: pr-5730

If the changes are expected, update the current_golden_images_cache hash in the circleci config to accept the new images. Instructions are included in that file.
If the changes are unexpected, you can investigate the cause of the differences and update the code accordingly.

Copy link
Contributor

Tachometer results

Currently, no packages are changed by this PR...

// Restore the cached `aria-label` if it exists
if (this.cachedAriaLabel) {
this.host.setAttribute('aria-label', this.cachedAriaLabel);
} else if (!pending) {
// If no cached `aria-label` and not `pending`, remove the `aria-label`
} else {
this.host.removeAttribute('aria-label');
Copy link
Contributor

Choose a reason for hiding this comment

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

You are now always removing aria-label If there is no cached label. Do you intend this to be removed even if it was never set? Maybe check for if this exists first?

// If the current `aria-label` is different from the pending label, cache it
// or if the cached `aria-label` is different from the current `aria-label`, cache it
if (
(!this.cachedAriaLabel &&
Copy link
Contributor

Choose a reason for hiding this comment

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

If this.cachedAriaLabel is undefined, isn't the second branch (this.cachedAriaLabel !== currentAriaLabel) always true? Also this is quite complex to read. Can you abstract these into a helper function, added a small snippet below if you want to take reference. Just making sure the main method is more readable

if (shouldCacheAriaLabel(this.cachedAriaLabel, currentAriaLabel, pendingLabel)) {
    this.cachedAriaLabel = currentAriaLabel;
}
...
function shouldCacheAriaLabel(cached, current, pending) {
    return (
        (!cached && current && current !== pending) ||
        (cached !== current && current && current !== pending)
    );
}

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.

2 participants