From fe2c2ab7afb0dccd149408288073070c6bf64779 Mon Sep 17 00:00:00 2001 From: Cory LaViska Date: Thu, 17 Jul 2025 11:56:41 -0400 Subject: [PATCH] improve accessibility; fixes #1177 (#1190) --- .../docs/docs/resources/changelog.md | 1 + .../animated-image/animated-image.css | 15 +++++++++- .../animated-image/animated-image.ts | 29 ++++++++++++++++--- packages/webawesome/src/translations/ar.ts | 2 ++ packages/webawesome/src/translations/cs.ts | 2 ++ packages/webawesome/src/translations/da.ts | 2 ++ packages/webawesome/src/translations/de.ts | 2 ++ packages/webawesome/src/translations/en.ts | 2 ++ packages/webawesome/src/translations/es.ts | 2 ++ packages/webawesome/src/translations/fa.ts | 2 ++ packages/webawesome/src/translations/fi.ts | 2 ++ packages/webawesome/src/translations/fr.ts | 2 ++ packages/webawesome/src/translations/he.ts | 6 ++-- packages/webawesome/src/translations/hr.ts | 2 ++ packages/webawesome/src/translations/hu.ts | 2 ++ packages/webawesome/src/translations/id.ts | 2 ++ packages/webawesome/src/translations/it.ts | 2 ++ packages/webawesome/src/translations/ja.ts | 2 ++ packages/webawesome/src/translations/nb.ts | 2 ++ packages/webawesome/src/translations/nl.ts | 2 ++ packages/webawesome/src/translations/nn.ts | 2 ++ packages/webawesome/src/translations/pl.ts | 2 ++ packages/webawesome/src/translations/pt.ts | 2 ++ packages/webawesome/src/translations/ru.ts | 2 ++ packages/webawesome/src/translations/sl.ts | 2 ++ packages/webawesome/src/translations/sv.ts | 2 ++ packages/webawesome/src/translations/tr.ts | 2 ++ packages/webawesome/src/translations/uk.ts | 2 ++ packages/webawesome/src/translations/zh-cn.ts | 2 ++ packages/webawesome/src/translations/zh-tw.ts | 2 ++ packages/webawesome/src/utilities/localize.ts | 2 ++ 31 files changed, 98 insertions(+), 7 deletions(-) diff --git a/packages/webawesome/docs/docs/resources/changelog.md b/packages/webawesome/docs/docs/resources/changelog.md index 987ac9869..600b2012b 100644 --- a/packages/webawesome/docs/docs/resources/changelog.md +++ b/packages/webawesome/docs/docs/resources/changelog.md @@ -26,6 +26,7 @@ Components with the Experimental badge sh - Fixed a bug in `` that caused slotted media to have incorrectly rounded corners [issue:1107] - Fixed a bug in `` that prevented pill buttons from rendering corners properly [issue:1165] - Fixed a bug in `` that caused some vertical groups to appear horizontal [issue:1152] +- Improved accessibility of `` so keyboard users can focus and toggle the animation [issue:1177] ## 3.0.0-beta.2 diff --git a/packages/webawesome/src/components/animated-image/animated-image.css b/packages/webawesome/src/components/animated-image/animated-image.css index 8e1ab5df2..59f659044 100644 --- a/packages/webawesome/src/components/animated-image/animated-image.css +++ b/packages/webawesome/src/components/animated-image/animated-image.css @@ -42,7 +42,7 @@ img[aria-hidden='true'] { } } -:host([play]:not(:hover)) .control-box { +:where(:host([play]:not(:hover))) .control-box { opacity: 0; } @@ -50,3 +50,16 @@ img[aria-hidden='true'] { :host(:not([play])) slot[name='pause-icon'] { display: none; } + +/* Show control box on keyboard focus */ +.animated-image { + &:focus { + outline: none; + } + + &:focus-visible .control-box { + opacity: 1; + outline: var(--wa-focus-ring); + outline-offset: var(--wa-focus-ring-offset); + } +} diff --git a/packages/webawesome/src/components/animated-image/animated-image.ts b/packages/webawesome/src/components/animated-image/animated-image.ts index b181ca6e0..f12ad4f06 100644 --- a/packages/webawesome/src/components/animated-image/animated-image.ts +++ b/packages/webawesome/src/components/animated-image/animated-image.ts @@ -4,6 +4,7 @@ import { WaErrorEvent } from '../../events/error.js'; import { WaLoadEvent } from '../../events/load.js'; import { watch } from '../../internal/watch.js'; import WebAwesomeElement from '../../internal/webawesome-element.js'; +import { LocalizeController } from '../../utilities/localize.js'; import '../icon/icon.js'; import styles from './animated-image.css'; @@ -30,6 +31,8 @@ import styles from './animated-image.css'; export default class WaAnimatedImage extends WebAwesomeElement { static css = styles; + private readonly localize = new LocalizeController(this); + @query('.animated') animatedImage: HTMLImageElement; @state() frozenFrame: string; @@ -48,6 +51,13 @@ export default class WaAnimatedImage extends WebAwesomeElement { this.play = !this.play; } + private handleKeyDown(event: KeyboardEvent) { + if (event.key === 'Enter' || event.key === ' ') { + event.preventDefault(); + this.play = !this.play; + } + } + private handleLoad() { const canvas = document.createElement('canvas'); const { width, height } = this.animatedImage; @@ -82,15 +92,26 @@ export default class WaAnimatedImage extends WebAwesomeElement { } render() { + const verb = this.localize.term(this.play ? 'pauseAnimation' : 'playAnimation'); + const label = `${verb} ${this.alt}`; + return html` -
+
${this.alt} @@ -102,10 +123,10 @@ export default class WaAnimatedImage extends WebAwesomeElement { src=${this.frozenFrame} alt=${this.alt} aria-hidden=${this.play ? 'true' : 'false'} - @click=${this.handleClick} + role="presentation" /> -
+