Skip to content

Commit

Permalink
fix(overlay): do not focus the trigger when closing an overlay, unles…
Browse files Browse the repository at this point in the history
…s expected
  • Loading branch information
Westbrook Johnson authored and Westbrook committed Dec 9, 2020
1 parent 35ecb2a commit bed817f
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion packages/overlay/src/overlay-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,23 @@ export class OverlayStack {
overlay.interaction === 'inline') &&
!overlay.tabbingAway)
) {
overlay.trigger.focus();
const overlayRoot = overlay.overlayContent.getRootNode() as ShadowRoot;
const overlayContentActiveElement =
overlayRoot.activeElement;
const triggerRoot = overlay.trigger.getRootNode() as ShadowRoot;
const triggerActiveElement = triggerRoot.activeElement;
if (
overlay.overlayContent.contains(
overlayContentActiveElement
) ||
overlay.trigger
.getRootNode()
.contains(triggerActiveElement) ||
(triggerRoot.host &&
triggerRoot.host.isSameNode(triggerActiveElement))
) {
overlay.trigger.focus();
}
}
overlay.tabbingAway = false;
}
Expand Down

0 comments on commit bed817f

Please sign in to comment.