From 2b18843d34e72a3f895ef2ab3b49a286e41c0a83 Mon Sep 17 00:00:00 2001 From: Ugo Stephant Date: Thu, 29 Sep 2022 09:36:17 +0200 Subject: [PATCH] fix(react): fix dropdown disabled state not closing upstream --- packages/react/lib/Dropdown/index.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/packages/react/lib/Dropdown/index.js b/packages/react/lib/Dropdown/index.js index f661285e1..852037d27 100644 --- a/packages/react/lib/Dropdown/index.js +++ b/packages/react/lib/Dropdown/index.js @@ -43,10 +43,7 @@ const Dropdown = forwardRef(({ }); const { x, y, reference, floating, strategy, context } = useFloating({ open: state.opened, - onOpenChange: o => { - dispatch({ opened: o }); - onToggle?.({ opened: o }); - }, + onOpenChange: (...args) => onOpenChange(...args), placement, strategy: 'fixed', whileElementsMounted: autoUpdate, @@ -88,6 +85,15 @@ const Dropdown = forwardRef(({ innerRef, })); + const onOpenChange = o => { + if (disabled && o) { + return; + } + + dispatch({ opened: o }); + onToggle?.({ opened: o }); + }; + const toggle = () => { if (disabled) { return;