Skip to content

Commit

Permalink
[AriaUtils]: Removing NVDA workaround for alert function
Browse files Browse the repository at this point in the history
Issue:
- The current alert function uses a workaround to avoid NVDA reading the alert message twice (NVDA bug: nvaccess/nvda#6680).
- However, understanding now that it breaks other SR program's functionality, we should implement it the correct way without working around NVDA's bug

Changes:
- Fixing implementation for ARIAUtils.alert
    - Instead of changing a description element for an alert element, we are applying the text change to the alert element directly.

Bug: 1120844
Change-Id: Ic4fc8a99a56b3ce61948c9cf91308adf0d72d30c
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2368771
Reviewed-by: Patrick Brosset <patrick.brosset@microsoft.com>
Commit-Queue: Michael Liao <michael.liao@microsoft.com>
  • Loading branch information
Michael Liao authored and Commit Bot committed Aug 24, 2020
1 parent a836dfd commit 844d99b
Showing 1 changed file with 9 additions and 18 deletions.
27 changes: 9 additions & 18 deletions front_end/ui/ARIAUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -625,39 +625,30 @@ function hideFromLayout(element) {
}

/**
* @type {!WeakMap<!Document, !{alertElement: !HTMLElement, messageElement: !HTMLElement}>}
* @type {!WeakMap<!Document, !HTMLElement>}>}
*/
const alertsMap = new WeakMap();

/**
* This function is used to announce a message with the screen reader.
* Setting the textContent would allow the SR to access the offscreen element via browse mode
* Due to existing NVDA bugs (https://github.com/nvaccess/nvda/issues/10140), setting the
* aria-label of the alert element results in the message being read twice.
* The current workaround is to set the aria-describedby of the alert element
* to a description element where the aria-label is set to the message.
* Due to existing NVDA bugs (https://github.com/nvaccess/nvda/issues/6680), this alert will
* be read twice for NVDA users.
* This function should work as expected for other supported screen reader programs.
* @param {string} message
* @param {!Element} element
*/
export function alert(message, element) {
const document = /** @type {!Document} */ (element.ownerDocument);

let alertElements = alertsMap.get(document);
if (!alertElements) {
const messageElement = /** @type {!HTMLElement} */ (document.body.createChild('div'));
const messageElementId = 'ariaLiveMessageElement';
messageElement.id = messageElementId;
hideFromLayout(messageElement);

const alertElement = /** @type {!HTMLElement} */ (document.body.createChild('div'));
let alertElement = alertsMap.get(document);
if (!alertElement) {
alertElement = /** @type {!HTMLElement} */ (document.body.createChild('div'));
hideFromLayout(alertElement);
alertElement.setAttribute('role', 'alert');
alertElement.setAttribute('aria-atomic', 'true');
alertElement.setAttribute('aria-describedby', messageElementId);

alertElements = {messageElement, alertElement};
alertsMap.set(document, alertElements);
alertsMap.set(document, alertElement);
}

setAccessibleName(alertElements.messageElement, message.trimEndWithMaxLength(10000));
setAccessibleName(alertElement, message.trimEndWithMaxLength(10000));
}

0 comments on commit 844d99b

Please sign in to comment.