Skip to content

Commit 26222dd

Browse files
committed
prevent loop onto documentElement
1 parent c41b395 commit 26222dd

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

dialog-polyfill.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,8 @@
529529
dialogPolyfill.DialogManager.prototype.handleFocus_ = function(event) {
530530
if (this.containedByTopDialog_(event.target)) { return; }
531531

532+
if (document.activeElement === document.documentElement) { return; }
533+
532534
event.preventDefault();
533535
event.stopPropagation();
534536
safeBlur(/** @type {Element} */ (event.target));
@@ -539,9 +541,11 @@
539541
var dialog = dpi.dialog;
540542
var position = dialog.compareDocumentPosition(event.target);
541543
if (position & Node.DOCUMENT_POSITION_PRECEDING) {
542-
if (this.forwardTab_) { // forward
544+
if (this.forwardTab_) {
545+
// forward
543546
dpi.focus_();
544-
} else { // backwards
547+
} else if (event.target !== document.documentElement) {
548+
// backwards if we're not already focused on <html>
545549
document.documentElement.focus();
546550
}
547551
} else {

tests/modal-dialog.html

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
<!DOCTYPE html>
2-
<html>
2+
<html tabindex="0">
33
<meta charset='utf-8'>
44
<head>
55
<script src="../dialog-polyfill.js"></script>
66
<meta name="viewport" content="width=device-width, user-scalable=no">
77
<link rel="stylesheet" type="text/css" href="../dialog-polyfill.css">
88
<style>
9+
html {
10+
border: 4px solid white;
11+
}
12+
html:focus {
13+
border-color: red;
14+
}
915
dialog {
1016
width: 100px;
1117
}

0 commit comments

Comments
 (0)