From 832f8d560dee8c3d5b4d1f25bbb555316b29dbdb Mon Sep 17 00:00:00 2001 From: Tanuj Mittal Date: Thu, 17 Sep 2020 15:08:46 -0700 Subject: [PATCH] Reset focus to trigger element when pane is closed (#217) --- src/Explorer/Panes/ContextualPaneBase.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/Explorer/Panes/ContextualPaneBase.ts b/src/Explorer/Panes/ContextualPaneBase.ts index 11aed8786..0f51620a8 100644 --- a/src/Explorer/Panes/ContextualPaneBase.ts +++ b/src/Explorer/Panes/ContextualPaneBase.ts @@ -9,6 +9,7 @@ import Explorer from "../Explorer"; // TODO: Use specific actions for logging telemetry data export abstract class ContextualPaneBase extends WaitsForTemplateViewModel { + private initalFocusedElement: HTMLElement | undefined; public id: string; public container: Explorer; public firstFieldHasFocus: ko.Observable; @@ -49,9 +50,11 @@ export abstract class ContextualPaneBase extends WaitsForTemplateViewModel { this.visible(false); this.isExecuting(false); this.resetData(); + this.resetFocus(); } public open() { + this.initalFocusedElement = document.activeElement as HTMLElement; this.visible(true); this.firstFieldHasFocus(true); this.resizePane(); @@ -123,4 +126,11 @@ export abstract class ContextualPaneBase extends WaitsForTemplateViewModel { $(paneElement).height(newPaneElementHeight); } + + private resetFocus(): void { + if (this.initalFocusedElement) { + this.initalFocusedElement.focus(); + this.initalFocusedElement = undefined; + } + } }