Skip to content

fix: base-button, update aria label on updated event. This also updated attr on slotchange event #5674

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

tsavka-adobe
Copy link

Description

Currently the aria-label attribute gets set on firstUpdate. This causes an issue when the button is rendered and then the prop is updated. The change is not getting reflected. This makes sure the change actually gets reflected.

Update:
aria-label gets removed on slotChange event as well. This PR sets aria-label on any change based on label prop value.

Motivation and context

Adobe Expres A11Y critical bug

Related issue(s)

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?

@tsavka-adobe tsavka-adobe requested a review from a team as a code owner August 6, 2025 03:40
Copy link

changeset-bot bot commented Aug 6, 2025

⚠️ No Changeset found

Latest commit: 2d2515f

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

@Rajdeepc Rajdeepc left a comment

Choose a reason for hiding this comment

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

A little test I have added. Please verify this from your end and let me know when you are ready for a re-review. Thanks for catching the bug and working on this. I will create a ticket for this.

it('preserves aria-label when slot content changes', async () => {
            const el = await fixture<Button>(html`
                <sp-button label="Test Label">
                    Initial Content
                </sp-button>
            `);

            await elementUpdated(el);
            expect(el.getAttribute('aria-label')).to.equal('Test Label');

            // Change the slot content
            el.textContent = 'Updated Content';
            await elementUpdated(el);

            // The aria-label should still be preserved
            expect(el.getAttribute('aria-label')).to.equal('Test Label');

            // Change slot content again
            el.innerHTML = '<span>New Content</span>';
            await elementUpdated(el);

            // The aria-label should still be preserved
            expect(el.getAttribute('aria-label')).to.equal('Test Label');
        });
        

Comment on lines -261 to -267
if (changes.has('label')) {
if (this.label) {
this.setAttribute('aria-label', this.label);
} else {
this.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.

In update it is still useful to track label changes.

Copy link
Author

Choose a reason for hiding this comment

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

Done.

@@ -243,6 +264,7 @@ export class ButtonBase extends ObserveSlotText(LikeAnchor(Focusable), '', [
this.manageAnchor();
}

this.updateAriaLabel();
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
this.updateAriaLabel();
if (changed.has('label')) {
this.updateAriaLabel();
}

Copy link
Author

Choose a reason for hiding this comment

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

Done.

* @label property is empty within changed propertyValues on slot change event.
* Need to check actualy @label property value instead.
*/
protected updateAriaLabel(): void {
Copy link
Contributor

Choose a reason for hiding this comment

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

Only update aria-label if we have a label property and we're not in a pending state. You need to account for these scenarios too. A minor update to your code would be.

- `<slot @slotchange=${this.manageTextObservedSlot}></slot>` 

+ `<slot @slotchange=${this.handleSlotChange}></slot>` 

private handleSlotChange(): void {
    // Call the original manageTextObservedSlot method
    this.manageTextObservedSlot();
    // Only update aria-label if we have a label property and we're not in a pending state
    if (this.label && !('pending' in this && (this as { pending: boolean }).pending === true)) {
        this.updateAriaLabel();
    }
 }
    

Copy link
Author

Choose a reason for hiding this comment

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

Done.

Copy link
Author

Choose a reason for hiding this comment

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

This seem to cause the issue. I reverted my original solution.

@Rajdeepc Rajdeepc added bug Something isn't working a11y Issues related to accessibility SEV 3 labels Aug 6, 2025
@tsavka-adobe
Copy link
Author

Thank you @Rajdeepc for recommendations. I updated another test that was failing as well.

@Rajdeepc
Copy link
Contributor

Rajdeepc commented Aug 6, 2025

@tsavka-adobe Can you add some testing criteria too so that other reviewers can verify?

Comment on lines +228 to +233
if (
'pending' in this &&
(this as { pending: boolean }).pending === true
) {
return;
}
Copy link
Author

Choose a reason for hiding this comment

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

Checking for pending state

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a11y Issues related to accessibility bug Something isn't working SEV 3
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants