From bc381be2640d726bf89dc353e17003939f5175af Mon Sep 17 00:00:00 2001 From: Sage Abdullah Date: Tue, 23 Jan 2024 14:26:09 +0000 Subject: [PATCH] Reset filters' w-drilldown state on close This fixes the issue where the state is stuck at the last opened filter when the drilldown's contents are replaced --- client/src/controllers/DrilldownController.ts | 10 ++++++++++ .../wagtailadmin/shared/headers/slim_header.html | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/client/src/controllers/DrilldownController.ts b/client/src/controllers/DrilldownController.ts index 633ffe0fbc..80467e16dd 100644 --- a/client/src/controllers/DrilldownController.ts +++ b/client/src/controllers/DrilldownController.ts @@ -57,6 +57,16 @@ export class DrilldownController extends Controller { this.activeSubmenuValue = ''; } + /** + * Delay closing the submenu to allow the top-level menu to fade out first. + * Useful for resetting the state when the user clicks outside the menu. + * This can be used as an action for the w-dropdown:hidden event of the menu, + * e.g. data-action="w-dropdown:hidden->w-drilldown#delayedClose". + */ + delayedClose() { + setTimeout(() => this.close(), 200); + } + /** * Derive the component’s targets based on the state, * so the drilldown state can be controlled externally more easily. diff --git a/wagtail/admin/templates/wagtailadmin/shared/headers/slim_header.html b/wagtail/admin/templates/wagtailadmin/shared/headers/slim_header.html index a1875c483d..7edb9936e9 100644 --- a/wagtail/admin/templates/wagtailadmin/shared/headers/slim_header.html +++ b/wagtail/admin/templates/wagtailadmin/shared/headers/slim_header.html @@ -79,7 +79,7 @@ {% endif %} {% if filters %} -
+
{% include "wagtailadmin/shared/headers/_filters.html" with filters=filters only %}
{% endif %}