restore focus (#9668)

* restore focus

* update default config

* update
This commit is contained in:
Alan Ren
2020-03-23 12:09:13 -07:00
committed by GitHub
parent aff5f2786d
commit 5a0dd18cba
2 changed files with 9 additions and 6 deletions

View File

@@ -345,8 +345,6 @@ export abstract class Modal extends Disposable implements IThemable {
this._modalBodySection.querySelectorAll(tabbableElementsQuerySelector) :
this._bodyContainer.querySelectorAll(tabbableElementsQuerySelector);
this._focusedElementBeforeOpen = <HTMLElement>document.activeElement;
if (focusableElements && focusableElements.length > 0) {
(<HTMLElement>focusableElements[0]).focus();
}
@@ -356,6 +354,7 @@ export abstract class Modal extends Disposable implements IThemable {
* Shows the modal and attaches key listeners
*/
protected show() {
this._focusedElementBeforeOpen = <HTMLElement>document.activeElement;
this._modalShowingContext.get()!.push(this._staticKey);
DOM.append(this.layoutService.container, this._bodyContainer);
this.setInitialFocusedElement();
@@ -396,14 +395,18 @@ export abstract class Modal extends Disposable implements IThemable {
protected hide() {
this._modalShowingContext.get()!.pop();
this._bodyContainer.remove();
if (this._focusedElementBeforeOpen) {
this._focusedElementBeforeOpen.focus();
}
this._keydownListener.dispose();
this._resizeListener.dispose();
this._telemetryService.createActionEvent(TelemetryKeys.TelemetryView.Shell, TelemetryKeys.ModalDialogClosed)
.withAdditionalProperties({ name: this._name })
.send();
this.restoreKeyboardFocus();
}
private restoreKeyboardFocus() {
if (this._focusedElementBeforeOpen) {
this._focusedElementBeforeOpen.focus();
}
}
/**