fix error message steal focus issue (#22782)

* fix steal focus issue

* update comment
This commit is contained in:
Alan Ren
2023-04-19 11:39:45 -07:00
committed by GitHub
parent 39a28c5f51
commit 35829acd00

View File

@@ -612,8 +612,11 @@ export abstract class Modal extends Disposable implements IThemable {
protected set messagesElementVisible(visible: boolean) {
if (visible) {
if (this._useDefaultMessageBoxLocation) {
DOM.prepend(this._modalContent!, this._messageElement!);
this.setInitialFocusedElement();
// To avoid stealing focus from the user, only reset the keyboard focus when the message is not currently visible.
if (!this._messageElement!.parentNode) {
DOM.prepend(this._modalContent!, this._messageElement!);
this.setInitialFocusedElement();
}
}
} else {
// only do the removal when the messageElement has parent element.