UX: ensures esc key is correctly working when in dates form (#9299)

UX: ensures esc key is correctly working when in dates form (#9299)

1 esc close modal focus date button in toolbar 2 esc reduces composer

diff --git a/plugins/discourse-local-dates/assets/javascripts/discourse/controllers/discourse-local-dates-create-modal.js.es6 b/plugins/discourse-local-dates/assets/javascripts/discourse/controllers/discourse-local-dates-create-modal.js.es6
new file mode 100644
index 0000000..103ac02
--- /dev/null
+++ b/plugins/discourse-local-dates/assets/javascripts/discourse/controllers/discourse-local-dates-create-modal.js.es6
@@ -0,0 +1,21 @@
+import Controller from "@ember/controller";
+import ModalFunctionality from "discourse/mixins/modal-functionality";
+import { schedule } from "@ember/runloop";
+
+export default Controller.extend(ModalFunctionality, {
+  onShow() {
+    schedule("afterRender", () => {
+      const fromButton = document.getElementById("from-date-time");
+      fromButton && fromButton.focus();
+    });
+  },
+
+  onClose() {
+    schedule("afterRender", () => {
+      const localDatesBtn = document.querySelector(
+        ".d-editor-button-bar .local-dates.btn"
+      );
+      localDatesBtn && localDatesBtn.focus();
+    });
+  }
+});
diff --git a/plugins/discourse-local-dates/assets/javascripts/discourse/templates/components/discourse-local-dates-create-form.hbs b/plugins/discourse-local-dates/assets/javascripts/discourse/templates/components/discourse-local-dates-create-form.hbs
index 30bc69e..92adae6 100644
--- a/plugins/discourse-local-dates/assets/javascripts/discourse/templates/components/discourse-local-dates-create-form.hbs
+++ b/plugins/discourse-local-dates/assets/javascripts/discourse/templates/components/discourse-local-dates-create-form.hbs
@@ -23,6 +23,7 @@
         <div class="date-time-control from {{if fromSelected 'is-selected'}} {{if fromFilled 'is-filled'}}">
           {{d-icon "calendar-alt"}}
           {{d-button
+            id="from-date-time"
             action=(action "focusFrom")
             translatedLabel=formattedFrom
             class="date-time"}}

GitHub sha: 6c2717ed

This commit appears in #9299 which was approved by eviltrout. It was merged by jjaffeux.