Skip to content

Commit

Permalink
fixes #103167
Browse files Browse the repository at this point in the history
  • Loading branch information
sbatten committed Jul 24, 2020
1 parent 86c04f7 commit f74e473
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
10 changes: 10 additions & 0 deletions src/vs/base/browser/dom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -749,6 +749,16 @@ export function getShadowRoot(domNode: Node): ShadowRoot | null {
return isShadowRoot(domNode) ? domNode : null;
}

export function getActiveElement(): Element | null {
let result = document.activeElement;

while (result?.shadowRoot) {
result = result.shadowRoot.activeElement;
}

return result;
}

export function createStyleSheet(container: HTMLElement = document.getElementsByTagName('head')[0]): HTMLStyleElement {
let style = document.createElement('style');
style.type = 'text/css';
Expand Down
4 changes: 2 additions & 2 deletions src/vs/base/browser/ui/actionbar/actionbar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ export class ActionBar extends Disposable implements IActionRunner {

this.focusTracker = this._register(DOM.trackFocus(this.domNode));
this._register(this.focusTracker.onDidBlur(() => {
if (document.activeElement === this.domNode || !DOM.isAncestor(document.activeElement, this.domNode)) {
if (DOM.getActiveElement() === this.domNode || !DOM.isAncestor(DOM.getActiveElement(), this.domNode)) {
this._onDidBlur.fire();
this.focusedItem = undefined;
}
Expand Down Expand Up @@ -214,7 +214,7 @@ export class ActionBar extends Disposable implements IActionRunner {
private updateFocusedItem(): void {
for (let i = 0; i < this.actionsList.children.length; i++) {
const elem = this.actionsList.children[i];
if (DOM.isAncestor(document.activeElement, elem)) {
if (DOM.isAncestor(DOM.getActiveElement(), elem)) {
this.focusedItem = i;
break;
}
Expand Down
2 changes: 1 addition & 1 deletion src/vs/base/browser/ui/contextview/contextview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ export class ContextView extends Disposable {
if (this.useShadowDOM) {
this.shadowRootHostElement = DOM.$('.shadow-root-host');
this.container.appendChild(this.shadowRootHostElement);
this.shadowRoot = this.shadowRootHostElement.attachShadow({ mode: 'closed' });
this.shadowRoot = this.shadowRootHostElement.attachShadow({ mode: 'open' });
this.shadowRoot.innerHTML = `
<style>
${SHADOW_ROOT_CSS}
Expand Down
8 changes: 4 additions & 4 deletions src/vs/base/browser/ui/menu/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import * as strings from 'vs/base/common/strings';
import { IActionRunner, IAction, SubmenuAction, Separator, IActionViewItemProvider } from 'vs/base/common/actions';
import { ActionBar, ActionsOrientation } from 'vs/base/browser/ui/actionbar/actionbar';
import { ResolvedKeybinding, KeyCode } from 'vs/base/common/keyCodes';
import { addClass, EventType, EventHelper, EventLike, removeTabIndexAndUpdateFocus, isAncestor, hasClass, addDisposableListener, removeClass, append, $, addClasses, removeClasses, clearNode, createStyleSheet, isInShadowDOM } from 'vs/base/browser/dom';
import { addClass, EventType, EventHelper, EventLike, removeTabIndexAndUpdateFocus, isAncestor, hasClass, addDisposableListener, removeClass, append, $, addClasses, removeClasses, clearNode, createStyleSheet, isInShadowDOM, isShadowRoot, getActiveElement } from 'vs/base/browser/dom';
import { StandardKeyboardEvent } from 'vs/base/browser/keyboardEvent';
import { RunOnceScheduler } from 'vs/base/common/async';
import { DisposableStore } from 'vs/base/common/lifecycle';
Expand Down Expand Up @@ -679,7 +679,7 @@ class SubmenuMenuActionViewItem extends BaseMenuActionViewItem {
}, 250);

this.hideScheduler = new RunOnceScheduler(() => {
if (this.element && (!isAncestor(document.activeElement, this.element) && this.parentData.submenu === this.mysubmenu)) {
if (this.element && (!isAncestor(getActiveElement(), this.element) && this.parentData.submenu === this.mysubmenu)) {
this.parentData.parent.focus(false);
this.cleanupExistingSubmenu(true);
}
Expand Down Expand Up @@ -713,7 +713,7 @@ class SubmenuMenuActionViewItem extends BaseMenuActionViewItem {
this._register(addDisposableListener(this.element, EventType.KEY_DOWN, e => {
let event = new StandardKeyboardEvent(e);

if (document.activeElement === this.item) {
if (getActiveElement() === this.item) {
if (event.equals(KeyCode.RightArrow) || event.equals(KeyCode.Enter)) {
EventHelper.stop(e, true);
}
Expand All @@ -733,7 +733,7 @@ class SubmenuMenuActionViewItem extends BaseMenuActionViewItem {
}));

this._register(addDisposableListener(this.element, EventType.FOCUS_OUT, e => {
if (this.element && !isAncestor(document.activeElement, this.element)) {
if (this.element && !isAncestor(getActiveElement(), this.element)) {
this.hideScheduler.schedule();
}
}));
Expand Down

0 comments on commit f74e473

Please sign in to comment.