-
Notifications
You must be signed in to change notification settings - Fork 231
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
base: main
Are you sure you want to change the base?
fix: base-button, update aria label on updated event. This also updated attr on slotchange event #5674
Conversation
|
There was a problem hiding this 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');
});
if (changes.has('label')) { | ||
if (this.label) { | ||
this.setAttribute('aria-label', this.label); | ||
} else { | ||
this.removeAttribute('aria-label'); | ||
} | ||
} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this.updateAriaLabel(); | |
if (changed.has('label')) { | |
this.updateAriaLabel(); | |
} |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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();
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
There was a problem hiding this comment.
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.
…m/tsavka-adobe/spectrum-web-components into tsavka-button-base-aria-label-fix
Thank you @Rajdeepc for recommendations. I updated another test that was failing as well. |
@tsavka-adobe Can you add some testing criteria too so that other reviewers can verify? |
if ( | ||
'pending' in this && | ||
(this as { pending: boolean }).pending === true | ||
) { | ||
return; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Checking for pending state
Description
Currently the
aria-label
attribute gets set onfirstUpdate
. 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 onslotChange
event as well. This PR setsaria-label
on any change based onlabel
prop value.Motivation and context
Adobe Expres A11Y critical bug
Related issue(s)
Screenshots (if appropriate)
Author's checklist
Reviewer's checklist
patch
,minor
, ormajor
featuresManual review test cases
Descriptive Test Statement
Descriptive Test Statement
Device review