From 6870dc71cd8a6514209c0808fd03330585d4d314 Mon Sep 17 00:00:00 2001 From: davfsa Date: Sat, 14 Jun 2025 23:14:58 +0200 Subject: [PATCH] fix: close dropdown menu when focus lost (#986) * fix: close dropdown menu when focus lost Signed-off-by: davfsa * fix: shadow var name to avoid unused lint Signed-off-by: davfsa * fix: remove unused argument Signed-off-by: davfsa --------- Signed-off-by: davfsa Co-authored-by: Jas Singh --- .../menus/shared/dropdown/index.tsx | 116 +++++++++--------- 1 file changed, 56 insertions(+), 60 deletions(-) diff --git a/src/components/menus/shared/dropdown/index.tsx b/src/components/menus/shared/dropdown/index.tsx index f594930..f8b2b7d 100644 --- a/src/components/menus/shared/dropdown/index.tsx +++ b/src/components/menus/shared/dropdown/index.tsx @@ -25,11 +25,21 @@ export default ({ name={name} namespace={name} className={`${name} dropdown-menu`} - onKeyPressEvent={(_, event) => { + onKeyPressEvent={(self, event) => { const key = event.get_keyval()[1]; if (key === Gdk.KEY_Escape) { - App.get_window(name)?.set_visible(false); + self.visible = false; + } + }} + onFocusOutEvent={(self) => { + self.visible = false; + }} + onButtonPressEvent={(self, event) => { + const buttonClicked = event.get_button()[1]; + + if (buttonClicked === Gdk.BUTTON_PRIMARY || buttonClicked === Gdk.BUTTON_SECONDARY) { + self.visible = false; } }} visible={false} @@ -48,67 +58,53 @@ export default ({ })} {...props} > - { - const buttonClicked = event.get_button()[1]; - - if (buttonClicked === Gdk.BUTTON_PRIMARY || buttonClicked === Gdk.BUTTON_SECONDARY) { - App.get_window(name)?.set_visible(false); + + {bind(location).as((lcn) => { + if (locationMap[lcn] === Astal.WindowAnchor.TOP) { + return ; } - }} - > - - {bind(location).as((lcn) => { - if (locationMap[lcn] === Astal.WindowAnchor.TOP) { - return ; - } - return ; - })} - { - const buttonClicked = event.get_button()[1]; + return ; + })} + { + const buttonClicked = event.get_button()[1]; - if ( - buttonClicked === Gdk.BUTTON_PRIMARY || - buttonClicked === Gdk.BUTTON_SECONDARY - ) { - return true; - } - }} - setup={(self) => { - globalEventBoxes.set({ - ...globalEventBoxes.get(), - [name]: self, - }); - }} - > - - { - App.connect('window-toggled', (_, window) => { - self.set_reveal_child(window.visible); - }); - }} - transitionType={transition} - transitionDuration={bind(options.menus.transitionTime)} - > - - {child} - - - - - {bind(location).as((lcn) => { - if (locationMap[lcn] === Astal.WindowAnchor.BOTTOM) { - return ; + if (buttonClicked === Gdk.BUTTON_PRIMARY || buttonClicked === Gdk.BUTTON_SECONDARY) { + return true; } - return ; - })} - - + }} + setup={(self) => { + globalEventBoxes.set({ + ...globalEventBoxes.get(), + [name]: self, + }); + }} + > + + { + App.connect('window-toggled', (_, window) => { + self.set_reveal_child(window.visible); + }); + }} + transitionType={transition} + transitionDuration={bind(options.menus.transitionTime)} + > + + {child} + + + + + {bind(location).as((lcn) => { + if (locationMap[lcn] === Astal.WindowAnchor.BOTTOM) { + return ; + } + return ; + })} + ); };