From 0dda9320f96ad0d9e2d1627c155683b87f37135b Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Fri, 3 Nov 2023 14:08:30 +0100 Subject: [PATCH] Close drop down menus before caching the page This avoids a flickering when closing modals coming back to the underlying page. --- .../components/solidus_admin/orders/show/component.html.erb | 2 +- admin/app/components/solidus_admin/orders/show/component.js | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/admin/app/components/solidus_admin/orders/show/component.html.erb b/admin/app/components/solidus_admin/orders/show/component.html.erb index 1c07d0b8a03..83578b71a2f 100644 --- a/admin/app/components/solidus_admin/orders/show/component.html.erb +++ b/admin/app/components/solidus_admin/orders/show/component.html.erb @@ -1,4 +1,4 @@ -<%= page do %> +<%= page("data-action": "turbo:before-cache@window->#{stimulus_id}#closeMenus") do %> <%= page_header do %> <%= page_header_back(solidus_admin.orders_path) %> <%= page_header_title(t('.title', number: @order.number)) %> diff --git a/admin/app/components/solidus_admin/orders/show/component.js b/admin/app/components/solidus_admin/orders/show/component.js index 6839d36996e..6c6056ac26d 100644 --- a/admin/app/components/solidus_admin/orders/show/component.js +++ b/admin/app/components/solidus_admin/orders/show/component.js @@ -1,5 +1,7 @@ import { Controller } from '@hotwired/stimulus' export default class extends Controller { - + closeMenus() { + this.event.querySelectorAll('details').forEach(details => details.removeAttribute('open')); + } }