From 2adda186a097038317496096479bdf700f15ff90 Mon Sep 17 00:00:00 2001 From: Sage Abdullah Date: Tue, 23 Jan 2024 23:53:40 +0000 Subject: [PATCH] Add cancelable w-dropdown:clickaway event for closing dropdown on click away --- client/src/controllers/DropdownController.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/client/src/controllers/DropdownController.ts b/client/src/controllers/DropdownController.ts index 6e7bc24e37..0c94b4a452 100644 --- a/client/src/controllers/DropdownController.ts +++ b/client/src/controllers/DropdownController.ts @@ -219,11 +219,19 @@ export class DropdownController extends Controller { // 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,