0
0
mirror of https://github.com/wagtail/wagtail.git synced 2024-11-25 05:02:57 +01:00

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
This commit is contained in:
Sage Abdullah 2024-01-23 14:26:09 +00:00 committed by Thibaud Colas
parent 238cbf3cd2
commit bc381be264
2 changed files with 11 additions and 1 deletions

View File

@ -57,6 +57,16 @@ export class DrilldownController extends Controller<HTMLElement> {
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 components targets based on the state,
* so the drilldown state can be controlled externally more easily.

View File

@ -79,7 +79,7 @@
{% endif %}
{% if filters %}
<div id="filters-drilldown" class="w-drilldown" data-controller="w-drilldown" data-action="w-swap:success@document->w-drilldown#updateParamsCount">
<div id="filters-drilldown" class="w-drilldown" data-controller="w-drilldown" data-action="w-swap:success@document->w-drilldown#updateParamsCount w-dropdown:hide->w-drilldown#delayedClose">
{% include "wagtailadmin/shared/headers/_filters.html" with filters=filters only %}
</div>
{% endif %}