Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.

Commit 9086b54

Browse files
Splaktarjosephperrott
authored andcommitted
fix(dialog): thread blocking during large DOM traversals (#10552) (#11193)
1 parent ecca532 commit 9086b54

File tree

1 file changed

+23
-12
lines changed

1 file changed

+23
-12
lines changed

src/components/dialog/dialog.js

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ function MdDialogDirective($$rAF, $mdTheming, $mdDialog) {
536536
* `three` into the controller, with the value 3. If `bindToController` is true, they will be
537537
* copied to the controller instead.
538538
* - `bindToController` - `bool`: bind the locals to the controller, instead of passing them in.
539-
* - `resolve` - `{function=}`: Similar to locals, except it takes as values functions that return promises, and the
539+
* - `resolve` - `{function=}`: Similar to locals, except it takes as values functions that return promises, and the
540540
* dialog will not open until all of the promises resolve.
541541
* - `controllerAs` - `{string=}`: An alias to assign the controller to on the scope.
542542
* - `parent` - `{element=}`: The element to append the dialog to. Defaults to appending
@@ -1145,35 +1145,46 @@ function MdDialogProvider($$interimElementProvider) {
11451145
// get raw DOM node
11461146
walkDOM(element[0]);
11471147

1148-
options.unlockScreenReader = function() {
1148+
options.unlockScreenReader = function () {
11491149
isHidden = false;
11501150
walkDOM(element[0]);
11511151

11521152
options.unlockScreenReader = null;
11531153
};
11541154

11551155
/**
1156-
* Walk DOM to apply or remove aria-hidden on sibling nodes
1157-
* and parent sibling nodes
1158-
*
1156+
* Get all of an element's parent elements up the DOM tree
1157+
* @return {Array} The parent elements
11591158
*/
1160-
function walkDOM(element) {
1159+
function getParents(element) {
1160+
var parents = [];
11611161
while (element.parentNode) {
11621162
if (element === document.body) {
1163-
return;
1163+
return parents;
11641164
}
11651165
var children = element.parentNode.children;
11661166
for (var i = 0; i < children.length; i++) {
11671167
// skip over child if it is an ascendant of the dialog
1168-
// or a script or style tag
1168+
// a script or style tag, or a live region.
11691169
if (element !== children[i] &&
1170-
!isNodeOneOf(children[i], ['SCRIPT', 'STYLE']) &&
1171-
!children[i].hasAttribute('aria-live')) {
1172-
children[i].setAttribute('aria-hidden', isHidden);
1170+
!isNodeOneOf(children[i], ['SCRIPT', 'STYLE']) &&
1171+
!children[i].hasAttribute('aria-live')) {
1172+
parents.push(children[i]);
11731173
}
11741174
}
1175+
element = element.parentNode;
1176+
}
1177+
return parents;
1178+
}
11751179

1176-
walkDOM(element = element.parentNode);
1180+
/**
1181+
* Walk DOM to apply or remove aria-hidden on sibling nodes
1182+
* and parent sibling nodes
1183+
*/
1184+
function walkDOM(element) {
1185+
var elements = getParents(element);
1186+
for (var i = 0; i < elements.length; i++) {
1187+
elements[i].setAttribute('aria-hidden', isHidden);
11771188
}
11781189
}
11791190
}

0 commit comments

Comments
 (0)