Repository navigation
Add an opt-in ariaNotify() transport for screen reader announcements #5962
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Eugene (OEvgeny)
wants to merge
11
commits into
main
Choose a base branch
from
OEvgeny/fix-aria-notify-transport
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
4ca9e61
Add styleOptions.announcementTransport to announce via ariaNotify()
552ca6f
Show the live region copy in ariaNotify snapshots
67dce49
Fall back to the live region without ariaNotify(), drop 'auto', do no…
6a36eab
Add the changelog fragment
6fea16c
Check ariaNotify() support once per realm, outside of effects
4df5e71
Explain why ariaNotify() support is checked lazily
f9fcb6f
Apply suggestion from @OEvgeny
OEvgeny 9e01bb4
Merge branch 'main' into OEvgeny/fix-aria-notify-transport
OEvgeny 6dd07ab
Empty the live region right after announcing via ariaNotify()
2a9dca4
Normalize announcementTransport with valibot fallback()
ed98b5b
Rename styleOptions.announcementTransport to assistiveTechnologyAnnou…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| ### Added | ||
|
|
||
| - 🧪 Added `styleOptions.assistiveTechnologyAnnouncementTransport` to announce via `ariaNotify()` instead of the live region, in PR [#5962](https://github.com/microsoft/BotFramework-WebChat/pull/5962), by [@OEvgeny](https://github.com/OEvgeny) |
129 changes: 129 additions & 0 deletions
129
__tests__/html2/accessibility/ariaNotify/adaptiveCard.inputValue.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,129 @@ | ||
| <!doctype html> | ||
| <html lang="en-US"> | ||
| <head> | ||
| <link href="/assets/index.css" rel="stylesheet" type="text/css" /> | ||
| <!-- Shows the live region, so the snapshot shows the copy the announcements are computed from. --> | ||
| <link href="/assets/accessibility.liveRegionAttachment.css" rel="stylesheet" type="text/css" /> | ||
| </head> | ||
| <body> | ||
| <main id="webchat"></main> | ||
| <script type="importmap"> | ||
| { | ||
| "imports": { | ||
| "@testduet/wait-for": "https://esm.sh/@testduet/wait-for", | ||
| "botframework-webchat": "/__dist__/packages/bundle/static/botframework-webchat.js", | ||
| "botframework-webchat/": "/__dist__/packages/bundle/static/botframework-webchat/", | ||
| "jest-mock": "https://esm.sh/jest-mock", | ||
| "react": "/__dist__/packages/bundle/static/react.js", | ||
| "react-dom": "/__dist__/packages/bundle/static/react-dom.js", | ||
| "react-dom/client": "/__dist__/packages/bundle/static/react-dom/client.js" | ||
| } | ||
| } | ||
| </script> | ||
| <script type="module"> | ||
| import '/test-harness.mjs'; | ||
| import '/test-page-object.mjs'; | ||
|
|
||
| import { waitFor } from '@testduet/wait-for'; | ||
| import { createStoreWithOptions, ReactWebChat } from 'botframework-webchat'; | ||
| import { spyOn } from 'jest-mock'; | ||
| import { createElement } from 'react'; | ||
| import { createRoot } from 'react-dom/client'; | ||
|
|
||
| // TODO: This is for `createDirectLineEmulator` only, should find ways to eliminate this line. | ||
| window.WebChat = { createStoreWithOptions }; | ||
|
|
||
| run(async function () { | ||
| // GIVEN: The browser supports `ariaNotify()`, recorded instead of announced. | ||
| const ariaNotify = spyOn(Element.prototype, 'ariaNotify').mockImplementation(() => {}); | ||
|
|
||
| const { directLine, store } = testHelpers.createDirectLineEmulator(); | ||
|
|
||
| // GIVEN: Web Chat sends announcements via `ariaNotify()`. | ||
| createRoot(document.getElementById('webchat')).render( | ||
| createElement(ReactWebChat, { | ||
| directLine, | ||
| store, | ||
| styleOptions: { | ||
| assistiveTechnologyAnnouncementTransport: 'aria-notify', | ||
| hideSendBox: true, | ||
| internalLiveRegionFadeAfter: 60000 // Would keep live region entries for 60 seconds, does not apply to `ariaNotify()`. | ||
| } | ||
| }) | ||
| ); | ||
|
|
||
| await pageConditions.uiConnected(); | ||
|
|
||
| // The connectivity notification is announced first, see `message.html`. | ||
| await waitFor(() => expect(ariaNotify).toHaveBeenCalledTimes(1)); | ||
| ariaNotify.mockClear(); | ||
|
|
||
| // WHEN: The bot sends an Adaptive Card form with named and pre-filled inputs, as in `liveRegion/attachment/adaptiveCard.inputValue.html`. | ||
| await directLine.emulateIncomingActivity({ | ||
| attachments: [ | ||
| { | ||
| content: { | ||
| $schema: 'http://adaptivecards.io/schemas/adaptive-card.json', | ||
| actions: [{ title: 'Place order', type: 'Action.Submit' }], | ||
| body: [ | ||
| { id: 'name', label: 'Your name', type: 'Input.Text', value: 'Ada' }, | ||
| { id: 'quantity', label: 'Quantity', type: 'Input.Number', value: 3 }, | ||
| { id: 'date', label: 'Delivery date', type: 'Input.Date', value: '2026-10-20' }, | ||
| { id: 'note', placeholder: 'Add a note', type: 'Input.Text' }, // No label: the card names it by its placeholder. | ||
| { | ||
| choices: [ | ||
| { title: 'Red', value: 'red' }, | ||
| { title: 'Blue', value: 'blue' } | ||
| ], | ||
| id: 'color', | ||
| label: 'Color', | ||
| type: 'Input.ChoiceSet', | ||
| value: 'blue' | ||
| }, | ||
| { id: 'gift', title: 'Gift wrap', type: 'Input.Toggle', value: 'true' } // Equals the default "valueOn": checked. | ||
| ], | ||
| type: 'AdaptiveCard', | ||
| version: '1.5' | ||
| }, | ||
| contentType: 'application/vnd.microsoft.card.adaptive' | ||
| } | ||
| ], | ||
| from: { role: 'bot' }, | ||
| type: 'message' | ||
| }); | ||
|
|
||
| await pageConditions.numActivitiesShown(1); | ||
|
|
||
| // THEN: The card is announced once, with every input of its live region copy read by name and value, then the button, followed by the note of the live region. | ||
| await waitFor(() => | ||
| expect(ariaNotify.mock.calls).toEqual([ | ||
| [ | ||
| [ | ||
| 'Bot said', | ||
| 'A card', | ||
| 'Your name Ada', | ||
| 'Quantity 3', | ||
| 'Delivery date 2026-10-20', | ||
| 'Add a note', // Empty: read by name only. | ||
| 'Color Blue', // The title of the selected choice. | ||
| 'Gift wrap', // Checkboxes are read by their label; "checked" is not read, it would need a localized word. | ||
| 'Place order' | ||
| ].join(' '), | ||
| { priority: 'normal' } | ||
| ], | ||
| [ | ||
| 'Message is interactive. Press shift tab key 2 to 3 times to switch to the chat history. Then click on the message to interact.', | ||
| { priority: 'normal' } | ||
| ] | ||
| ]) | ||
| ); | ||
|
|
||
| // THEN: The live region is emptied right after announcing, without waiting 60 seconds: its copy of the card is only rendered to compute the text. | ||
| await waitFor(() => expect(pageElements.liveRegion().childElementCount).toBe(0)); | ||
|
|
||
| // THEN: The live region (top) is empty, there is nothing for screen readers to read from it; the transcript shows the form. | ||
| await host.snapshot('local'); | ||
| }); | ||
| </script> | ||
| </body> | ||
| </html> |
Binary file added
BIN
+12.4 KB
__tests__/html2/accessibility/ariaNotify/adaptiveCard.inputValue.html.snap-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| <!doctype html> | ||
| <html lang="en-US"> | ||
| <head> | ||
| <link href="/assets/index.css" rel="stylesheet" type="text/css" /> | ||
| <!-- Shows the live region, so the snapshot shows the copy the announcements are computed from. --> | ||
| <link href="/assets/accessibility.liveRegionAttachment.css" rel="stylesheet" type="text/css" /> | ||
| </head> | ||
| <body> | ||
| <main id="webchat"></main> | ||
| <script type="importmap"> | ||
| { | ||
| "imports": { | ||
| "@testduet/wait-for": "https://esm.sh/@testduet/wait-for", | ||
| "botframework-webchat": "/__dist__/packages/bundle/static/botframework-webchat.js", | ||
| "botframework-webchat/": "/__dist__/packages/bundle/static/botframework-webchat/", | ||
| "jest-mock": "https://esm.sh/jest-mock", | ||
| "react": "/__dist__/packages/bundle/static/react.js", | ||
| "react-dom": "/__dist__/packages/bundle/static/react-dom.js", | ||
| "react-dom/client": "/__dist__/packages/bundle/static/react-dom/client.js" | ||
| } | ||
| } | ||
| </script> | ||
| <script type="module"> | ||
| import '/test-harness.mjs'; | ||
| import '/test-page-object.mjs'; | ||
|
|
||
| import { waitFor } from '@testduet/wait-for'; | ||
| import { createStoreWithOptions, ReactWebChat } from 'botframework-webchat'; | ||
| import { spyOn } from 'jest-mock'; | ||
| import { createElement } from 'react'; | ||
| import { createRoot } from 'react-dom/client'; | ||
|
|
||
| // TODO: This is for `createDirectLineEmulator` only, should find ways to eliminate this line. | ||
| window.WebChat = { createStoreWithOptions }; | ||
|
|
||
| run(async function () { | ||
| // GIVEN: The browser supports `ariaNotify()`, recorded instead of announced. | ||
| const ariaNotify = spyOn(Element.prototype, 'ariaNotify').mockImplementation(() => {}); | ||
|
|
||
| const { directLine, store } = testHelpers.createDirectLineEmulator(); | ||
|
|
||
| // GIVEN: Web Chat sends announcements via `ariaNotify()`. | ||
| createRoot(document.getElementById('webchat')).render( | ||
| createElement(ReactWebChat, { | ||
| directLine, | ||
| store, | ||
| styleOptions: { | ||
| assistiveTechnologyAnnouncementTransport: 'aria-notify', | ||
| hideSendBox: true, | ||
| internalLiveRegionFadeAfter: 60000 // Would keep live region entries for 60 seconds, does not apply to `ariaNotify()`. | ||
| } | ||
| }) | ||
| ); | ||
|
|
||
| await pageConditions.uiConnected(); | ||
|
|
||
| // The connectivity notification is announced first, see `message.html`. | ||
| await waitFor(() => expect(ariaNotify).toHaveBeenCalledTimes(1)); | ||
| ariaNotify.mockClear(); | ||
|
|
||
| // WHEN: The bot sends a hero card with an image and two buttons. | ||
| await directLine.emulateIncomingActivity({ | ||
| attachments: [ | ||
| { | ||
| content: { | ||
| buttons: [ | ||
| { title: 'Tomorrow', type: 'imBack', value: 'Tomorrow' }, | ||
| { title: 'Next week', type: 'imBack', value: 'Next week' } | ||
| ], | ||
| images: [{ alt: 'Bot avatar', url: '/assets/bot-avatar.jpg' }], | ||
| subtitle: 'Seattle', | ||
| text: 'Sunny, no umbrella needed.', | ||
| title: 'Weather today' | ||
| }, | ||
| contentType: 'application/vnd.microsoft.card.hero' | ||
| } | ||
| ], | ||
| from: { role: 'bot' }, | ||
| type: 'message' | ||
| }); | ||
|
|
||
| await pageConditions.numActivitiesShown(1); | ||
| await pageConditions.allImagesLoaded(); | ||
|
|
||
| // THEN: The card is announced once, with the alt text of the image and the buttons as separate words ("Tomorrow Next week", not "TomorrowNext week"), then its note. | ||
| await waitFor(() => | ||
| expect(ariaNotify.mock.calls).toEqual([ | ||
| [ | ||
| 'Bot said A card Weather today Seattle Sunny, no umbrella needed. Bot avatar Tomorrow Next week', | ||
| { priority: 'normal' } | ||
| ], | ||
| // The buttons make the message interactive. | ||
| [ | ||
| 'Message is interactive. Press shift tab key 2 to 3 times to switch to the chat history. Then click on the message to interact.', | ||
| { priority: 'normal' } | ||
| ] | ||
| ]) | ||
| ); | ||
|
|
||
| // THEN: The live region is emptied right after announcing, without waiting 60 seconds: its copy of the card is only rendered to compute the text. | ||
| await waitFor(() => expect(pageElements.liveRegion().childElementCount).toBe(0)); | ||
|
|
||
| // THEN: The live region (top) is empty, there is nothing for screen readers to read from it; the transcript shows the hero card. | ||
| await host.snapshot('local'); | ||
| }); | ||
| </script> | ||
| </body> | ||
| </html> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
83 changes: 83 additions & 0 deletions
83
__tests__/html2/accessibility/ariaNotify/hostHidesLiveRegion.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| <!doctype html> | ||
| <html lang="en-US"> | ||
| <head> | ||
| <link href="/assets/index.css" rel="stylesheet" type="text/css" /> | ||
| <style> | ||
| /* The host page hides the live region of Web Chat from everyone, including screen readers. */ | ||
| .webchat__live-region { | ||
| display: none !important; | ||
| } | ||
| </style> | ||
| </head> | ||
| <body> | ||
| <main id="webchat"></main> | ||
| <script type="importmap"> | ||
| { | ||
| "imports": { | ||
| "@testduet/wait-for": "https://esm.sh/@testduet/wait-for", | ||
| "botframework-webchat": "/__dist__/packages/bundle/static/botframework-webchat.js", | ||
| "botframework-webchat/": "/__dist__/packages/bundle/static/botframework-webchat/", | ||
| "jest-mock": "https://esm.sh/jest-mock", | ||
| "react": "/__dist__/packages/bundle/static/react.js", | ||
| "react-dom": "/__dist__/packages/bundle/static/react-dom.js", | ||
| "react-dom/client": "/__dist__/packages/bundle/static/react-dom/client.js" | ||
| } | ||
| } | ||
| </script> | ||
| <script type="module"> | ||
| import '/test-harness.mjs'; | ||
| import '/test-page-object.mjs'; | ||
|
|
||
| import { waitFor } from '@testduet/wait-for'; | ||
| import { createStoreWithOptions, ReactWebChat } from 'botframework-webchat'; | ||
| import { spyOn } from 'jest-mock'; | ||
| import { createElement } from 'react'; | ||
| import { createRoot } from 'react-dom/client'; | ||
|
|
||
| // TODO: This is for `createDirectLineEmulator` only, should find ways to eliminate this line. | ||
| window.WebChat = { createStoreWithOptions }; | ||
|
|
||
| run(async function () { | ||
| // GIVEN: The browser supports `ariaNotify()`, recorded instead of announced. | ||
| const ariaNotify = spyOn(Element.prototype, 'ariaNotify').mockImplementation(() => {}); | ||
|
|
||
| const { directLine, store } = testHelpers.createDirectLineEmulator(); | ||
|
|
||
| // GIVEN: Web Chat sends announcements via `ariaNotify()`. | ||
| createRoot(document.getElementById('webchat')).render( | ||
| createElement(ReactWebChat, { | ||
| directLine, | ||
| store, | ||
| styleOptions: { assistiveTechnologyAnnouncementTransport: 'aria-notify', hideSendBox: true } | ||
| }) | ||
| ); | ||
|
|
||
| await pageConditions.uiConnected(); | ||
|
|
||
| // WHEN: The bot sends a message. | ||
| await directLine.emulateIncomingActivity({ | ||
| from: { role: 'bot' }, | ||
| text: 'Hello, **World**!', | ||
| type: 'message' | ||
| }); | ||
|
|
||
| await pageConditions.numActivitiesShown(1); | ||
|
|
||
| // THEN: The message is still announced, on the root element of Web Chat, which the host page did not hide. | ||
| await waitFor(() => | ||
| expect(ariaNotify.mock.calls).toEqual([ | ||
| ['connected', { priority: 'normal' }], // The connectivity notification, see `message.html`. | ||
| ['Bot said Hello, World!', { priority: 'normal' }] | ||
| ]) | ||
| ); | ||
| expect(ariaNotify.mock.contexts).toEqual([ | ||
| document.querySelector('.webchat'), | ||
| document.querySelector('.webchat') | ||
| ]); | ||
|
|
||
| // THEN: The live region is not shown (hidden by the host page); the transcript shows the message. | ||
| await host.snapshot('local'); | ||
| }); | ||
| </script> | ||
| </body> | ||
| </html> |
Binary file added
BIN
+4.42 KB
__tests__/html2/accessibility/ariaNotify/hostHidesLiveRegion.html.snap-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure about the visual screen reader is correct or not after we switch to
ariaNotify.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was misleading: the box is
.webchat__live-regionun-hidden by test CSS, showing anaria-hiddencopy nobody reads. Since 6dd07ab it is empty in'aria-notify'mode; what is announced is asserted via theariaNotify()spy.