Skip to content

Commit

Permalink
fix: change avatar default role attribute to img (#8427)
Browse files Browse the repository at this point in the history
  • Loading branch information
web-padawan authored Jan 2, 2025
1 parent 8463c9f commit 9a742f8
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 24 deletions.
1 change: 1 addition & 0 deletions packages/avatar-group/src/vaadin-avatar-group-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ export const AvatarGroupMixin = (superClass) =>

this._overflowController = new SlotController(this, 'overflow', 'vaadin-avatar', {
initializer: (overflow) => {
overflow.setAttribute('role', 'button');
overflow.setAttribute('aria-haspopup', 'menu');
overflow.setAttribute('aria-expanded', 'false');
overflow.addEventListener('click', (e) => this._onOverflowClick(e));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ snapshots["vaadin-avatar-group items"] =
`<vaadin-avatar-group aria-label="Currently 2 active users">
<vaadin-avatar
abbr="YY"
role="button"
role="img"
tabindex="0"
with-tooltip=""
>
Expand All @@ -33,7 +33,7 @@ snapshots["vaadin-avatar-group items"] =
<vaadin-avatar
abbr="TV"
name="Tomi Virkki"
role="button"
role="img"
tabindex="0"
with-tooltip=""
>
Expand Down Expand Up @@ -63,7 +63,7 @@ snapshots["vaadin-avatar-group theme"] =
>
<vaadin-avatar
abbr="YY"
role="button"
role="img"
tabindex="0"
theme="small"
with-tooltip=""
Expand All @@ -74,7 +74,7 @@ snapshots["vaadin-avatar-group theme"] =
<vaadin-avatar
abbr="TV"
name="Tomi Virkki"
role="button"
role="img"
tabindex="0"
theme="small"
with-tooltip=""
Expand Down Expand Up @@ -104,7 +104,7 @@ snapshots["vaadin-avatar-group opened default"] =
<vaadin-avatar
abbr="AD"
name="Abc Def"
role="button"
role="img"
tabindex="0"
with-tooltip=""
>
Expand All @@ -114,7 +114,7 @@ snapshots["vaadin-avatar-group opened default"] =
<vaadin-avatar
abbr="GJ"
name="Ghi Jkl"
role="button"
role="img"
tabindex="0"
with-tooltip=""
>
Expand Down Expand Up @@ -157,7 +157,7 @@ snapshots["vaadin-avatar-group opened overlay"] =
abbr="MP"
aria-hidden="true"
name="Mno Pqr"
role="button"
role="img"
tabindex="-1"
>
</vaadin-avatar>
Expand All @@ -172,7 +172,7 @@ snapshots["vaadin-avatar-group opened overlay"] =
abbr="SV"
aria-hidden="true"
name="Stu Vwx"
role="button"
role="img"
tabindex="-1"
>
</vaadin-avatar>
Expand Down Expand Up @@ -204,7 +204,7 @@ snapshots["vaadin-avatar-group opened overlay class"] =
abbr="MP"
aria-hidden="true"
name="Mno Pqr"
role="button"
role="img"
tabindex="-1"
>
</vaadin-avatar>
Expand All @@ -219,7 +219,7 @@ snapshots["vaadin-avatar-group opened overlay class"] =
abbr="SV"
aria-hidden="true"
name="Stu Vwx"
role="button"
role="img"
tabindex="-1"
>
</vaadin-avatar>
Expand Down
4 changes: 2 additions & 2 deletions packages/avatar/src/vaadin-avatar-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,9 @@ export const AvatarMixin = (superClass) =>
this.__updateVisibility();

// By default, if the user hasn't provided a custom role,
// the role attribute is set to "button".
// the role attribute is set to "img".
if (!this.hasAttribute('role')) {
this.setAttribute('role', 'button');
this.setAttribute('role', 'img');
}

if (!this.hasAttribute('tabindex')) {
Expand Down
8 changes: 4 additions & 4 deletions packages/avatar/test/avatar.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -366,8 +366,8 @@ describe('vaadin-avatar', () => {
});

describe('a11y', () => {
it('should set role="button" on the avatar', () => {
expect(avatar.getAttribute('role')).to.equal('button');
it('should set role="img" on the avatar', () => {
expect(avatar.getAttribute('role')).to.equal('img');
});

it('should set aria-hidden="true" on the img element', () => {
Expand All @@ -386,8 +386,8 @@ describe('vaadin-avatar', () => {
});

it('should not override custom role set on the avatar', () => {
const custom = fixtureSync('<vaadin-avatar role="image"></vaadin-avatar>');
expect(custom.getAttribute('role')).to.equal('image');
const custom = fixtureSync('<vaadin-avatar role="button"></vaadin-avatar>');
expect(custom.getAttribute('role')).to.equal('button');
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ snapshots["vaadin-message-list items"] =
abbr="JD"
aria-hidden="true"
name="Jane Doe"
role="button"
role="img"
slot="avatar"
tabindex="-1"
>
Expand All @@ -39,7 +39,7 @@ snapshots["vaadin-message-list items"] =
abbr="LR"
aria-hidden="true"
name="Lina Roy"
role="button"
role="img"
slot="avatar"
tabindex="-1"
>
Expand All @@ -64,7 +64,7 @@ snapshots["vaadin-message-list theme"] =
abbr="A"
aria-hidden="true"
name="Admin"
role="button"
role="img"
slot="avatar"
tabindex="-1"
>
Expand All @@ -89,7 +89,7 @@ snapshots["vaadin-message-list className"] =
abbr="A"
aria-hidden="true"
name="Admin"
role="button"
role="img"
slot="avatar"
tabindex="-1"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ snapshots["vaadin-message avatar username"] =
abbr="JD"
aria-hidden="true"
name="Joan Doe"
role="button"
role="img"
slot="avatar"
tabindex="-1"
>
Expand All @@ -77,7 +77,7 @@ snapshots["vaadin-message avatar abbr"] =
<vaadin-avatar
abbr="JD"
aria-hidden="true"
role="button"
role="img"
slot="avatar"
tabindex="-1"
>
Expand All @@ -91,7 +91,7 @@ snapshots["vaadin-message avatar img"] =
<vaadin-avatar
aria-hidden="true"
img="data:image/gif;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs="
role="button"
role="img"
slot="avatar"
tabindex="-1"
>
Expand All @@ -105,7 +105,7 @@ snapshots["vaadin-message avatar userColorIndex"] =
<vaadin-avatar
aria-hidden="true"
has-color-index=""
role="button"
role="img"
slot="avatar"
style="--vaadin-avatar-user-color: var(--vaadin-user-color-2);"
tabindex="-1"
Expand Down

0 comments on commit 9a742f8

Please sign in to comment.