Skip to content

Commit

Permalink
fix(cc-img): populate alt value
Browse files Browse the repository at this point in the history
Fixes #726
  • Loading branch information
HeleneAmouzou committed Oct 30, 2023
1 parent 8cfaffb commit a5d2d2b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/components/cc-img/cc-img.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,16 @@ export class CcImg extends LitElement {
}

render () {
const altValue = this.text ?? '';
const isLoading = (this.src != null && !this._loaded && !this._error);
const isSkeleton = (this.skeleton || isLoading);
const displayText = (this.src == null || this._error);
return html`
<div class="wrapper ${classMap({ skeleton: isSkeleton, loaded: this._loaded, text: displayText })}">
<img src=${ifDefined(this.src ?? undefined)} @load=${this._onLoad} @error=${this._onError} alt="">
<img src=${ifDefined(this.src ?? undefined)} @load=${this._onLoad} @error=${this._onError} alt=${altValue}>
${displayText ? html`
<div class="error-msg">${this.text}</div>
<!-- We use aria-hidden because we already have an alt value. -->
<div class="error-msg" aria-hidden="true">${this.text}</div>
` : ''}
</div>
`;
Expand Down
2 changes: 1 addition & 1 deletion src/components/cc-img/cc-img.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const conf = {
export const defaultStory = makeStory(conf, {
items: [
{ text: 'OMG' },
{ text: 'OMG', skeleton: true },
{ skeleton: true },
{ text: 'OMG', skeleton: true, src: 'http://placekitten.com/200/200' },
],
});
Expand Down

0 comments on commit a5d2d2b

Please sign in to comment.