From 8cc0d05cb01246f3b7240c34183255c07ca94c46 Mon Sep 17 00:00:00 2001 From: Liam DeBeasi Date: Thu, 13 Apr 2023 15:11:21 +0000 Subject: [PATCH 01/15] test(toast): update tests --- core/src/components/toast/test/a11y/index.html | 14 +++++++------- core/src/components/toast/test/a11y/toast.e2e.ts | 12 ++++-------- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/core/src/components/toast/test/a11y/index.html b/core/src/components/toast/test/a11y/index.html index 9e8b0c63510..204526fb91e 100644 --- a/core/src/components/toast/test/a11y/index.html +++ b/core/src/components/toast/test/a11y/index.html @@ -18,16 +18,16 @@

Toast - a11y

- - + + + +
From 2fe530d25af8097ab04f783868b7cc4b0653fbac Mon Sep 17 00:00:00 2001 From: Liam DeBeasi Date: Thu, 13 Apr 2023 15:05:06 -0400 Subject: [PATCH 05/15] fix(toast): nvda announces toast --- .../src/components/toast/test/a11y/index.html | 5 ++++ core/src/components/toast/toast.tsx | 26 ++++++++++++++++--- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/core/src/components/toast/test/a11y/index.html b/core/src/components/toast/test/a11y/index.html index e69382cc320..842bd16ae17 100644 --- a/core/src/components/toast/test/a11y/index.html +++ b/core/src/components/toast/test/a11y/index.html @@ -49,6 +49,11 @@

Toast - a11y

const updateContent = () => { const toasts = document.querySelectorAll('ion-toast'); + /** + * Note: Multiple updates to the props + * may cause screen readers like NVDA to announce + * the entire content multiple times. + */ toasts.forEach((toast) => { toast.header = 'Updated Header'; toast.message = 'Updated Message'; diff --git a/core/src/components/toast/toast.tsx b/core/src/components/toast/toast.tsx index 8fbe885d852..e5a990c15ab 100644 --- a/core/src/components/toast/toast.tsx +++ b/core/src/components/toast/toast.tsx @@ -1,5 +1,5 @@ import type { ComponentInterface, EventEmitter } from '@stencil/core'; -import { Watch, Component, Element, Event, h, Host, Method, Prop } from '@stencil/core'; +import { Watch, Component, Element, Event, h, Host, Method, Prop, State } from '@stencil/core'; import { config } from '../../global/config'; import { getIonMode } from '../../global/ionic-global'; @@ -55,6 +55,16 @@ export class Toast implements ComponentInterface, OverlayInterface { presented = false; + /** + * Some screen readers such as NVDA do not + * announce content with aria-live that + * is initially hidden. To work around this, + * we set aria-hidden="true" and then remove + * the aria-hidden once the toast content is + * fully visible. + */ + @State() revealContentToScreenReader = false; + @Element() el!: HTMLIonToastElement; /** @@ -268,6 +278,9 @@ export class Toast implements ComponentInterface, OverlayInterface { this.position ); await this.currentTransition; + + this.revealContentToScreenReader = true; + this.currentTransition = undefined; if (this.duration > 0) { @@ -303,6 +316,7 @@ export class Toast implements ComponentInterface, OverlayInterface { if (dismissed) { this.delegateController.removeViewFromDom(); + this.revealContentToScreenReader = false; } return dismissed; @@ -421,7 +435,7 @@ export class Toast implements ComponentInterface, OverlayInterface { } render() { - const { layout, el } = this; + const { layout, el, revealContentToScreenReader } = this; const allButtons = this.getButtons(); const startButtons = allButtons.filter((b) => b.side === 'start'); const endButtons = allButtons.filter((b) => b.side !== 'start'); @@ -466,7 +480,13 @@ export class Toast implements ComponentInterface, OverlayInterface { )} -
+
{this.header !== undefined && (
{this.header} From 85bed9c94225edba91e8892dae664436a38cb94a Mon Sep 17 00:00:00 2001 From: Liam DeBeasi Date: Thu, 13 Apr 2023 19:02:44 -0400 Subject: [PATCH 06/15] commit this before i break something --- .../src/components/toast/test/a11y/index.html | 8 +++--- core/src/components/toast/toast.tsx | 26 ++++++++++++++----- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/core/src/components/toast/test/a11y/index.html b/core/src/components/toast/test/a11y/index.html index 842bd16ae17..b2eb88a7ae1 100644 --- a/core/src/components/toast/test/a11y/index.html +++ b/core/src/components/toast/test/a11y/index.html @@ -18,7 +18,7 @@

Toast - a11y

- + Present Inline Toast Toast - a11y message="Inline Toast Message" > - + - + Update Inner Content