diff --git a/docs/resources/changelog.md b/docs/resources/changelog.md index 7b1f2e9c3..0bd2e6d57 100644 --- a/docs/resources/changelog.md +++ b/docs/resources/changelog.md @@ -8,6 +8,7 @@ _During the beta period, these restrictions may be relaxed in the event of a mis ## Next +- 🚨 BREAKING: changed the `alt` attribute to `label` in `` for consistency with other components - Added `role="status"` to `` - Fixed broken spinner animation in Safari [#633](https://github.com/shoelace-style/shoelace/issues/633) - Fixed an a11y bug in `` where `aria-describedby` referenced an id in the shadow root diff --git a/src/components/avatar/avatar.test.ts b/src/components/avatar/avatar.test.ts index 165b8d749..c964aacef 100644 --- a/src/components/avatar/avatar.test.ts +++ b/src/components/avatar/avatar.test.ts @@ -8,7 +8,7 @@ describe('', () => { describe('when provided no parameters', async () => { before(async () => { - el = await fixture(html` `); + el = await fixture(html` `); }); it('passes accessibility test', async () => { @@ -22,18 +22,18 @@ describe('', () => { }); }); - describe('when provided an image and alt parameter', async () => { + describe('when provided an image and label parameter', async () => { const image = 'https://images.unsplash.com/photo-1529778873920-4da4926a72c2?ixlib=rb-1.2.1&auto=format&fit=crop&w=300&q=80'; - const alt = 'Gray tabby kitten looking down'; + const label = 'Gray tabby kitten looking down'; before(async () => { - el = await fixture(html``); + el = await fixture(html``); }); it('passes accessibility test', async () => { /** * The image element itself is ancillary, because it's parent container contains the - * aria-label which dictates what "sl-avatar" is. This also implies that alt text will + * aria-label which dictates what "sl-avatar" is. This also implies that label text will * resolve to "" when not provided and ignored by readers. This is why we use alt="" on * the image element to pass accessibility. * https://html.spec.whatwg.org/multipage/images.html#ancillary-images @@ -47,17 +47,15 @@ describe('', () => { expect(part.getAttribute('src')).to.eq(image); }); - it('renders the alt attribute in the "base" part', async () => { + it('renders the label attribute in the "base" part', async () => { const part = el.shadowRoot?.querySelector('[part="base"]') as HTMLElement; - expect(part.getAttribute('aria-label')).to.eq(alt); + expect(part.getAttribute('aria-label')).to.eq(label); }); describe('when an error occurs when attempting to load the image', async () => { before(async () => { - el = await fixture( - html`` - ); + el = await fixture(html``); }); it('does not render the "image" part', async () => { @@ -71,7 +69,7 @@ describe('', () => { describe('when provided initials parameter', async () => { const initials = 'SL'; before(async () => { - el = await fixture(html``); + el = await fixture(html``); }); it('passes accessibility test', async () => { @@ -88,7 +86,7 @@ describe('', () => { ['square', 'rounded', 'circle'].forEach(shape => { describe(`when passed a shape attribute ${shape}`, () => { before(async () => { - el = await fixture(html``); + el = await fixture(html``); }); it('passes accessibility test', async () => { @@ -106,7 +104,7 @@ describe('', () => { describe('when passed a , on slot "icon"', async () => { before(async () => { - el = await fixture(html`random content`); + el = await fixture(html`random content`); }); it('passes accessibility test', async () => { diff --git a/src/components/avatar/avatar.ts b/src/components/avatar/avatar.ts index df8c20469..6bd85f69e 100644 --- a/src/components/avatar/avatar.ts +++ b/src/components/avatar/avatar.ts @@ -29,8 +29,8 @@ export default class SlAvatar extends LitElement { /** The image source to use for the avatar. */ @property() image: string; - /** Alternative text for the image. */ - @property() alt: string; + /** A label to use to describe the avatar to assistive devices. */ + @property() label: string; /** Initials to use as a fallback when no image is available (1-2 characters max recommended). */ @property() initials: string; @@ -49,7 +49,7 @@ export default class SlAvatar extends LitElement { 'avatar--square': this.shape === 'square' })} role="img" - aria-label=${this.alt} + aria-label=${this.label} > ${this.initials ? html`
${this.initials}
`