diff --git a/app/assets/javascripts/discourse/app/components/d-modal.js b/app/assets/javascripts/discourse/app/components/d-modal.js index 3b3354215ac..63e9e755dfa 100644 --- a/app/assets/javascripts/discourse/app/components/d-modal.js +++ b/app/assets/javascripts/discourse/app/components/d-modal.js @@ -1,3 +1,4 @@ +import afterTransition from "discourse/lib/after-transition"; import I18n from "I18n"; import { next } from "@ember/runloop"; import { on } from "discourse-common/utils/decorators"; @@ -116,5 +117,15 @@ export default Component.extend({ } else { this.set("dismissable", true); } + + if (this.element) { + const autofocusInputs = this.element.querySelectorAll( + ".modal-body input[autofocus]" + ); + + if (autofocusInputs.length) { + afterTransition(() => autofocusInputs[0].focus()); + } + } }, }); diff --git a/app/assets/javascripts/discourse/app/controllers/insert-hyperlink.js b/app/assets/javascripts/discourse/app/controllers/insert-hyperlink.js index e5600310560..d3821b2aa38 100644 --- a/app/assets/javascripts/discourse/app/controllers/insert-hyperlink.js +++ b/app/assets/javascripts/discourse/app/controllers/insert-hyperlink.js @@ -26,8 +26,6 @@ export default Controller.extend(ModalFunctionality, { element .closest(".modal-inner-container") .addEventListener("mousedown", this.mouseDown); - - document.activeElement.blur(); }); },