FIX: Add check for if element doesnt exist on ensureDropClosed (#13256)

FIX: Add check for if element doesnt exist on ensureDropClosed (#13256)

diff --git a/app/assets/javascripts/discourse/app/components/navigation-bar.js b/app/assets/javascripts/discourse/app/components/navigation-bar.js
index 5c354a8..546841c 100644
--- a/app/assets/javascripts/discourse/app/components/navigation-bar.js
+++ b/app/assets/javascripts/discourse/app/components/navigation-bar.js
@@ -52,6 +52,10 @@ export default Component.extend(FilterModeMixin, {
   },
 
   ensureDropClosed() {
+    if (!this.element || this.isDestroying || this.isDestroyed) {
+      return;
+    }
+
     if (this.expanded) {
       this.set("expanded", false);
     }
@@ -75,17 +79,13 @@ export default Component.extend(FilterModeMixin, {
             this.element.querySelector(".drop").style.display = "none";
 
             next(() => {
-              if (!this.element || this.isDestroying || this.isDestroyed) {
-                return;
-              }
-              this.set("expanded", false);
+              this.ensureDropClosed();
             });
-
             return true;
           });
 
           $(window).on("click.navigation-bar", () => {
-            this.set("expanded", false);
+            this.ensureDropClosed();
             return true;
           });
         });

GitHub sha: 188ac1c5

This commit appears in #13256 which was approved by jjaffeux. It was merged by jordanvidrine.