Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[menus] Restore the focus for context menu and main menu bar (fixes #481) #535

Merged
merged 1 commit into from
Sep 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions packages/core/src/browser/menu/browser-context-menu-renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,9 @@ export class BrowserContextMenuRenderer implements ContextMenuRenderer {
render(path: string, anchor: Anchor, onHide?: () => void): void {
const contextMenu = this.menuFactory.createContextMenu(path);
const { x, y } = anchor instanceof MouseEvent ? { x: anchor.clientX, y: anchor.clientY } : anchor;
const previouslyActive = window.document.activeElement as HTMLElement;
contextMenu.aboutToClose.connect(() => {
previouslyActive.focus();
if (onHide) {
onHide();
}
});
if (onHide) {
contextMenu.aboutToClose.connect(() => onHide());
}
contextMenu.open(x, y);
}

Expand Down
12 changes: 12 additions & 0 deletions packages/core/src/browser/menu/browser-menu-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ class DynamicMenuBarWidget extends MenuBarWidget {
super['_openChildMenu']();
};
}

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

empty line

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have agreed on such formatting? I do like it better with an empty line (not that I really want to get into a discussion about it :-))

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have not discussed it I assumed it from the rest of the code and I also prefer that...
It looked like a left over to me since no other code was touched in that function.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It actually was a formatting change, because I like that empty line :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can maybe discuss how to go about such things in today's meeting.

}
/**
* A menu widget that would recompute its items on update
Expand All @@ -115,6 +116,17 @@ class DynamicMenuWidget extends MenuWidget {
this.updateSubMenus(this, this.menu, this.options.commands);
}

public open(x: number, y: number, options?: MenuWidget.IOpenOptions): void {
// we want to restore the focus after the menu closes.
const previouslyActive = window.document.activeElement as HTMLElement;
const cb = () => {
previouslyActive.focus();
this.aboutToClose.disconnect(cb);
};
this.aboutToClose.connect(cb);
super.open(x, y, options);
}

private updateSubMenus(parent: MenuWidget, menu: CompositeMenuNode, commands: PhosphorCommandRegistry): void {
for (const item of menu.children) {
if (item instanceof CompositeMenuNode) {
Expand Down