Skip to content

Commit

Permalink
Improved accessibility:
Browse files Browse the repository at this point in the history
* converse-avatar:
  * Fix alt_text parameter that was ignored
  * using aria-label instead of alt attribute on svg (alt is not valid)
  * if no alt_text, adding role="presentation" so that screen readers
    ignores the image
  * when fallbacking on initials, adding a aria-label with the full name
  • Loading branch information
JohnXLivingston authored and jcbrand committed Aug 22, 2024
1 parent 940468e commit 365553d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/shared/avatar/avatar.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export default class Avatar extends CustomElement {
width: this.width,
image: data_uri || `data:${image_type};base64,${image}`,
image_type,
alt_text: this.name
});
}

Expand All @@ -52,8 +53,9 @@ export default class Avatar extends CustomElement {
line-height: ${this.height}px;`;

const author_style = this.model.getAvatarStyle(css);
return html`<div class="avatar-initials" style="${until(author_style, default_bg_css + css)}">
${this.getInitials(this.name)}
return html`<div class="avatar-initials" style="${until(author_style, default_bg_css + css)}"
aria-label="${this.name}">
${this.getInitials(this.name)}
</div>`;
}

Expand Down
4 changes: 3 additions & 1 deletion src/shared/avatar/templates/avatar.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { html } from 'lit';
import { html, nothing } from 'lit';

/**
* @param {string} image
Expand All @@ -15,6 +15,8 @@ export default (o) => {
class="avatar ${o.classes}"
width="${o.width}"
height="${o.height}"
aria-label="${o.alt_text}"
role=${o.alt_text ? nothing : 'presentation'}
>
<image
width="${o.width}"
Expand Down

0 comments on commit 365553d

Please sign in to comment.