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

Add cancelable w-dropdown:clickaway event for closing dropdown on click away

This commit is contained in:
Sage Abdullah 2024-01-23 23:53:40 +00:00 committed by Thibaud Colas
parent 6de3f84e9f
commit 2adda186a0

View File

@ -219,11 +219,19 @@ export class DropdownController extends Controller<HTMLElement> {
// function, so we need to get these ahead in time.
const reference = this.reference;
const toggleTarget = this.toggleTarget;
const dispatch = this.dispatch.bind(this);
return {
name: 'hideTooltipOnClickAway',
fn(instance: Instance) {
const onClick = (e: MouseEvent) => {
const event = dispatch('clickaway', {
cancelable: true,
detail: { target: e.target },
});
if (event.defaultPrevented) {
return;
}
if (
instance.state.isShown &&
// Hide if the click is outside of the reference element,