From 491297be82daed64ca7a4f1c1bbdee840442714c Mon Sep 17 00:00:00 2001 From: Alan Ren Date: Wed, 11 Aug 2021 23:11:33 -0700 Subject: [PATCH] update modal.ts (#16736) --- src/sql/workbench/browser/modal/modal.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/sql/workbench/browser/modal/modal.ts b/src/sql/workbench/browser/modal/modal.ts index cd391e9ac0..1665753387 100644 --- a/src/sql/workbench/browser/modal/modal.ts +++ b/src/sql/workbench/browser/modal/modal.ts @@ -598,10 +598,14 @@ export abstract class Modal extends Disposable implements IThemable { DOM.prepend(this._modalContent!, this._messageElement!); } } else { - DOM.removeNode(this._messageElement!); - // Set the focus to first focus element if the focus is not within the dialog - if (!DOM.isAncestor(document.activeElement, this._bodyContainer!)) { - this.setInitialFocusedElement(); + // only do the removal when the messageElement has parent element. + if (this._messageElement!.parentElement) { + // Reset the focus if keyboard focus is currently in the message area. + const resetFocus = DOM.isAncestor(document.activeElement, this._messageElement!); + this._messageElement!.remove(); + if (resetFocus) { + this.setInitialFocusedElement(); + } } } }