update modal.ts (#16736)

This commit is contained in:
Alan Ren
2021-08-11 23:11:33 -07:00
committed by GitHub
parent 1e761bc159
commit 491297be82

View File

@@ -598,10 +598,14 @@ export abstract class Modal extends Disposable implements IThemable {
DOM.prepend(this._modalContent!, this._messageElement!); DOM.prepend(this._modalContent!, this._messageElement!);
} }
} else { } else {
DOM.removeNode(this._messageElement!); // only do the removal when the messageElement has parent element.
// Set the focus to first focus element if the focus is not within the dialog if (this._messageElement!.parentElement) {
if (!DOM.isAncestor(document.activeElement, this._bodyContainer!)) { // Reset the focus if keyboard focus is currently in the message area.
this.setInitialFocusedElement(); const resetFocus = DOM.isAncestor(document.activeElement, this._messageElement!);
this._messageElement!.remove();
if (resetFocus) {
this.setInitialFocusedElement();
}
} }
} }
} }