From 46a8b68b9f31afb16b2ea89ea35ed37b309a6b06 Mon Sep 17 00:00:00 2001 From: Chris Zhu Date: Fri, 22 Nov 2024 18:49:31 -0800 Subject: [PATCH] ctrk to close --- app/javascript/controllers/theme_controller.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/app/javascript/controllers/theme_controller.js b/app/javascript/controllers/theme_controller.js index f20a15bc..ec0f6901 100644 --- a/app/javascript/controllers/theme_controller.js +++ b/app/javascript/controllers/theme_controller.js @@ -56,10 +56,18 @@ export default class extends Controller { } searchModalToggle() { + const searchModal = document.getElementById("search_modal"); + + // If modal is already open, close it and return + if (searchModal.open) { + searchModal.close(); + return; + } + + // Otherwise, proceed with opening the modal const searchInput = this.searchInputTarget; searchInput.focus(); searchInput.value = ""; - const searchModal = document.getElementById("search_modal"); searchModal.showModal(); this._searchInput(""); }