Skip to content

Commit

Permalink
overlay or descendat feature
Browse files Browse the repository at this point in the history
  • Loading branch information
pdgago committed Aug 3, 2017
1 parent fb161b4 commit 64369b2
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion overlay-container.html
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@

__onOverlayClosed(event) {
const overlay = this.__getLastOverlay();
if (overlay) {
if (overlay && !this.__isOverlayOrDescendantFocused(overlay)) {
overlay.focus();
}
this.__updateBackdrop();
Expand Down Expand Up @@ -135,6 +135,27 @@
}
}

__isOverlayOrDescendantFocused(overlay) {
const activeElement = this.__getDeepActiveElement();
if (activeElement) {
let node = activeElement;
while(node && node !== this) {
if (node === overlay) {
return true;
}
node = node.parentNode || node.host;
}
}
return false;
}

__getDeepActiveElement() {
var activeElement = document.activeElement;
while (activeElement && activeElement.shadowRoot && activeElement.shadowRoot.activeElement)
activeElement = activeElement.shadowRoot.activeElement;
return activeElement;
}

}

customElements.define(OverlayContainer.is, OverlayContainer);
Expand Down

0 comments on commit 64369b2

Please sign in to comment.