Skip to content

Commit f897f5e

Browse files
author
Eugene Olonov
committed
Hide line containers in the live region from the accessibility tree
Screen readers on Windows read "group" before every line of a new message: generic <div> and <p> are exposed as UIA Group. Lines and containers in the live region copy are now role="none"; only the aria-atomic message, its text, and the interactive copies (buttons, inputs) remain.
1 parent a3ba84e commit f897f5e

13 files changed

Lines changed: 56 additions & 35 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ Legends:
6363
- Fixed video and animation cards disappearing in production builds when the video URL is relative or invalid, in PR [#5889](https://github.com/microsoft/BotFramework-WebChat/pull/5889), by [@OEvgeny](https://github.com/OEvgeny)
6464
- Fixed timestamps always using the 12-hour clock, such as "4:41 PM" instead of "16:41" in German, in PR [#5920](https://github.com/microsoft/BotFramework-WebChat/pull/5920), by [@OEvgeny](https://github.com/OEvgeny)
6565
- Fixed screen readers saying "article" before new messages and their attachments in the live region, in PR [#XXXX](https://github.com/microsoft/BotFramework-WebChat/pull/XXXX), by [@OEvgeny](https://github.com/OEvgeny)
66+
- Fixed screen readers saying "article" and "group" before new messages and each of their lines in the live region, in PR [#XXXX](https://github.com/microsoft/BotFramework-WebChat/pull/XXXX), by [@OEvgeny](https://github.com/OEvgeny)
6667

6768
## [4.19.2] - 2026-10-08
6869

__tests__/html2/accessibility/liveRegion/attachment/genericWrappers.html renamed to __tests__/html2/accessibility/liveRegion/noRoleWords.html

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232

3333
await pageConditions.uiConnected();
3434

35-
// WHEN: Bot sends a message with an Adaptive Card, a hero card, and a file.
35+
// WHEN: Bot sends a message with an Adaptive Card, a hero card, a file, and a suggested action.
3636
await directLine.emulateIncomingActivity({
3737
attachments: [
3838
{
@@ -52,23 +52,29 @@
5252
{ contentType: 'application/octet-stream', name: 'report.zip' }
5353
],
5454
from: { role: 'bot' },
55+
suggestedActions: { actions: [{ title: 'Help', type: 'imBack', value: 'help' }] },
5556
text: 'Here are 2 cards and a file.',
5657
type: 'message'
5758
});
5859

5960
await pageConditions.numActivitiesShown(1);
6061

61-
await waitFor(() =>
62-
expect(pageElements.liveRegion().querySelector('.webchat__live-region-activity')).toBeTruthy()
63-
);
62+
const liveRegionActivity = await waitFor(() => {
63+
const element = pageElements.liveRegion().querySelector('.webchat__live-region-activity');
64+
65+
expect(element).toBeTruthy();
6466

65-
const liveRegionActivity = pageElements.liveRegion().querySelector('.webchat__live-region-activity');
67+
return element;
68+
});
6669

67-
// THEN: The live region should contain the text of the message, the cards, and the file.
70+
// THEN: The live region should contain the text of the message, the suggested action, the cards, and the file.
6871
expect(liveRegionActivity.innerText).toBe(
6972
[
7073
'Bot WC said:',
7174
'Here are 2 cards and a file.',
75+
'', // The suggested actions are in a `<p>`, `innerText` puts a blank line around it.
76+
'Help',
77+
'',
7278
'A card: Card 1',
7379
'OK',
7480
'A card: Card 2 Hero text',
@@ -80,15 +86,23 @@
8086
// THEN: The message should still be announced as a whole.
8187
expect(liveRegionActivity.getAttribute('aria-atomic')).toBe('true');
8288

83-
// THEN: The message and its attachments should not be articles, screen readers would read "article" before each of them.
8489
const accessibilityNodes = await Promise.all(
8590
[liveRegionActivity, ...liveRegionActivity.querySelectorAll('*')].map(element =>
8691
testHelpers.getAccessibilityNode(element)
8792
)
8893
);
8994

90-
expect(accessibilityNodes.map(({ role }) => role?.value)).not.toContain('article');
91-
expect(liveRegionActivity.querySelectorAll('article')).toHaveLength(0);
95+
// THEN: The message should be a generic container, not an article, screen readers would read "article" before it.
96+
expect(accessibilityNodes[0].role?.value).toBe('generic');
97+
98+
// THEN: Inside the message, only the copies of the buttons should be in the accessibility tree, besides the text.
99+
// On Windows, every other element is a "group" (including generic `<div>` and `<p>`), screen readers would read "group" before each line.
100+
expect(
101+
accessibilityNodes
102+
.slice(1) // The message itself keeps `aria-atomic`, which requires an element in the accessibility tree.
103+
.filter(({ ignored }) => !ignored)
104+
.map(({ name, role }) => `${role?.value} "${name?.value}"`)
105+
).toEqual(['button "Help"', 'button "OK"', 'button "Go"']);
92106
});
93107
</script>
94108
</body>

‎docs/ACCESSIBILITY.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ To make the live region more consistent across browsers and easier to control, w
279279
- Screen reader only reads the chat history marked as live region
280280
- Web Chat does not narrate attachment contents: attachments can be customized and the DOM tree could be very complex with interactive elements
281281
- Empty messages will be narrated if they have suggested actions
282+
- Lines and containers in the copy are `role="none"`, otherwise screen readers on Windows read "group" before every line; custom `attachmentForScreenReaderMiddleware` should do the same
282283
- The live region contains activities that were recently
283284
- When the DOM element appear in the live region, the screen reader will compute the alternative text and queue it for narration in a first-come-first-serve manner
284285
- The screen reader will keep the alternative text in the queue even after the DOM element is removed from the live region

‎packages/bundle/src/adaptiveCards/AttachmentForScreenReader/AdaptiveCardAttachment.js‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const AdaptiveCardChoiceSetInput = ({ input: { choices, defaultValue, label } })
3232
const defaultChoice = choices.find(({ value }) => defaultValue === value || (!defaultValue && !value));
3333

3434
return (
35-
<div>
35+
<div role="none">
3636
<select
3737
aria-label={label}
3838
aria-labelledby={!label && defaultChoice ? labelId : undefined}
@@ -117,8 +117,8 @@ const AdaptiveCardAttachment = ({ content }) => {
117117
const cardLabel = localize('ATTACHMENT_CARD', card.speak || '', '', '');
118118

119119
return (
120-
<div>
121-
<div>{cardLabel}</div>
120+
<div role="none">
121+
<div role="none">{cardLabel}</div>
122122
{inputs.map((input, index) =>
123123
input instanceof ChoiceSetInput ? (
124124
<AdaptiveCardChoiceSetInput input={input} key={index} />
@@ -133,7 +133,7 @@ const AdaptiveCardAttachment = ({ content }) => {
133133
<input placeholder={input.placeholder} tabIndex={-1} type="number" />
134134
</label>
135135
) : input instanceof OpenUrlAction || input instanceof ShowCardAction || input instanceof SubmitAction ? (
136-
<div key={index}>
136+
<div key={index} role="none">
137137
<button tabIndex={-1} type="button">
138138
{input.title}
139139
</button>

‎packages/bundle/src/adaptiveCards/AttachmentForScreenReader/RichCardAttachment.js‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ const RichCardAttachment = ({ content = {} }) => {
1616
const cardLabel = localize('ATTACHMENT_CARD', title || '', subtitle || '', text || '');
1717

1818
return (
19-
<div>
20-
<div>{cardLabel}</div>
19+
<div role="none">
20+
<div role="none">{cardLabel}</div>
2121
{!!image && !!image.alt && <img alt={image.alt} />}
2222
{!!images && !!images.length && images.map(({ alt }, index) => <img alt={alt} key={index} />)}
2323
{!!facts && !!facts.length && (
@@ -35,32 +35,32 @@ const RichCardAttachment = ({ content = {} }) => {
3535
{items.map(({ image, price, quantity, subtitle, text, title }, index) => (
3636
<li key={index}>
3737
{!!image && !!image.alt && <img alt={image.alt} />}
38-
{!!title && <p>{title}</p>}
39-
{!!subtitle && <p>{subtitle}</p>}
40-
{!!text && <p>{text}</p>}
41-
{!!quantity && <p>{quantity}</p>}
42-
{!!price && <p>{price}</p>}
38+
{!!title && <p role="none">{title}</p>}
39+
{!!subtitle && <p role="none">{subtitle}</p>}
40+
{!!text && <p role="none">{text}</p>}
41+
{!!quantity && <p role="none">{quantity}</p>}
42+
{!!price && <p role="none">{price}</p>}
4343
</li>
4444
))}
4545
</ul>
4646
)}
4747
{!!vat && (
48-
<p>
48+
<p role="none">
4949
{vatLabel} {vat}
5050
</p>
5151
)}
5252
{!!tax && (
53-
<p>
53+
<p role="none">
5454
{taxLabel} {tax}
5555
</p>
5656
)}
5757
{!!total && (
58-
<p>
58+
<p role="none">
5959
{totalLabel} {total}
6060
</p>
6161
)}
6262
{!!buttons && !!buttons.length && (
63-
<div>
63+
<div role="none">
6464
{buttons.map(({ title }, index) => (
6565
<button key={index} tabIndex={-1} type="button">
6666
{title}

‎packages/component/src/LiveRegion/LiveRegionActivity.tsx‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,16 @@ function LiveRegionActivity(props: LiveRegionActivityProps) {
5656
).replace(/\s{2,}/gu, ' ');
5757
const validFallbackText = fallbackText && typeof fallbackText === 'string';
5858

59+
// Lines are `role="none"`: on Windows, generic `<div>` and `<p>` are exposed as "group", screen readers would read "group" before each line.
60+
// The message itself stays in the accessibility tree, as required by `aria-atomic`.
5961
return (
6062
<div aria-atomic={true} className={classNames('webchat__live-region-activity', rootClassName)}>
61-
<div>{greetingAlt}</div>
63+
<div role="none">{greetingAlt}</div>
6264
{validFallbackText ? (
63-
<div>{fallbackText}</div>
65+
<div role="none">{fallbackText}</div>
6466
) : (
6567
<Fragment>
66-
<div>{textAlt}</div>
68+
<div role="none">{textAlt}</div>
6769
{type === 'message' && (
6870
<Fragment>
6971
{!!activity.suggestedActions && (

‎packages/component/src/LiveRegion/private/LiveRegionAttachments.tsx‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,13 @@ const LiveRegionAttachments = ({ activity }: LiveRegionAttachmentsProps) => {
3737
<Fragment>
3838
{attachmentForScreenReaderRenderers.map((render, index) => (
3939
// Direct Line does not have key for attachment other than index.
40+
// Like the lines of the message, `role="none"` keeps "group" from being read, see `LiveRegionActivity`.
4041
// eslint-disable-next-line react/no-array-index-key
41-
<div key={index}>{typeof render === 'function' && render()}</div>
42+
<div key={index} role="none">
43+
{typeof render === 'function' && render()}
44+
</div>
4245
))}
43-
{numAttachmentsAlt && <p>{numAttachmentsAlt}</p>}
46+
{numAttachmentsAlt && <p role="none">{numAttachmentsAlt}</p>}
4447
</Fragment>
4548
);
4649
};

‎packages/component/src/LiveRegion/private/LiveRegionSuggestedActions.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function LiveRegionSuggestedActions(props: LiveRegionSuggestedActionsProps) {
2424

2525
return (
2626
suggestedActions.actions?.length && (
27-
<p className="webchat__live-region-activity__suggested-actions">
27+
<p className="webchat__live-region-activity__suggested-actions" role="none">
2828
{suggestedActions.actions.map((action, index) => (
2929
// Direct Line schema does not have key other than index.
3030
// eslint-disable-next-line react/no-array-index-key

‎packages/component/src/Middleware/AttachmentForScreenReader/AudioAttachment.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const AudioAttachment = () => {
88

99
const label = localize('ATTACHMENT_AUDIO');
1010

11-
return <div>{label}</div>;
11+
return <div role="none">{label}</div>;
1212
};
1313

1414
export default AudioAttachment;

‎packages/component/src/Middleware/AttachmentForScreenReader/FileAttachment.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const FileAttachment = ({ attachment: { name = '' } = {} }) => {
99

1010
const label = localize('ATTACHMENT_FILE', name);
1111

12-
return <div>{label}</div>;
12+
return <div role="none">{label}</div>;
1313
};
1414

1515
FileAttachment.propTypes = {

0 commit comments

Comments
 (0)