Skip to content

Commit 52a923c

Browse files
author
Benjamin Pasero
committed
1 parent b5c75f3 commit 52a923c

1 file changed

Lines changed: 22 additions & 20 deletions

File tree

src/vs/base/browser/ui/aria/aria.ts

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -33,48 +33,50 @@ export function setARIAContainer(parent: HTMLElement) {
3333
/**
3434
* Given the provided message, will make sure that it is read as alert to screen readers.
3535
*/
36-
export function alert(msg: string): void {
37-
insertMessage(alertContainer, msg);
36+
export function alert(msg: string, disableRepeat?: boolean): void {
37+
insertMessage(alertContainer, msg, disableRepeat);
3838
}
3939

4040
/**
4141
* Given the provided message, will make sure that it is read as status to screen readers.
4242
*/
43-
export function status(msg: string): void {
43+
export function status(msg: string, disableRepeat?: boolean): void {
4444
if (isMacintosh) {
45-
alert(msg); // VoiceOver does not seem to support status role
45+
alert(msg, disableRepeat); // VoiceOver does not seem to support status role
4646
} else {
47-
insertMessage(statusContainer, msg);
47+
insertMessage(statusContainer, msg, disableRepeat);
4848
}
4949
}
5050

5151
let repeatedTimes = 0;
5252
let prevText: string | undefined = undefined;
53-
function insertMessage(target: HTMLElement, msg: string): void {
53+
function insertMessage(target: HTMLElement, msg: string, disableRepeat?: boolean): void {
5454
if (!ariaContainer) {
55-
// console.warn('ARIA support needs a container. Call setARIAContainer() first.');
5655
return;
5756
}
5857

59-
if (prevText === msg) {
60-
repeatedTimes++;
61-
}
62-
else {
63-
prevText = msg;
64-
repeatedTimes = 0;
65-
}
58+
// If the same message should be inserted that is already present, a screen reader would
59+
// not announce this message because it matches the previous one. As a workaround, we
60+
// alter the message with the number of occurences unless this is explicitly disabled
61+
// via the disableRepeat flag.
62+
if (!disableRepeat) {
63+
if (prevText === msg) {
64+
repeatedTimes++;
65+
} else {
66+
prevText = msg;
67+
repeatedTimes = 0;
68+
}
6669

67-
68-
switch (repeatedTimes) {
69-
case 0: break;
70-
case 1: msg = nls.localize('repeated', "{0} (occurred again)", msg); break;
71-
default: msg = nls.localize('repeatedNtimes', "{0} (occurred {1} times)", msg, repeatedTimes); break;
70+
switch (repeatedTimes) {
71+
case 0: break;
72+
case 1: msg = nls.localize('repeated', "{0} (occurred again)", msg); break;
73+
default: msg = nls.localize('repeatedNtimes', "{0} (occurred {1} times)", msg, repeatedTimes); break;
74+
}
7275
}
7376

7477
dom.clearNode(target);
7578
target.textContent = msg;
7679

77-
7880
// See https://www.paciellogroup.com/blog/2012/06/html5-accessibility-chops-aria-rolealert-browser-support/
7981
target.style.visibility = 'hidden';
8082
target.style.visibility = 'visible';

0 commit comments

Comments
 (0)