From 846e180bd5ebef89d10e12531e69978c7cb3278b Mon Sep 17 00:00:00 2001 From: wes337 Date: Sat, 19 Feb 2022 10:50:17 +0200 Subject: [PATCH 1/2] [@mantine/core] Select: only use open/close callback when value changes --- src/mantine-core/src/components/Select/Select.tsx | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/mantine-core/src/components/Select/Select.tsx b/src/mantine-core/src/components/Select/Select.tsx index 9f646fefba3..84a4cd8dcf2 100644 --- a/src/mantine-core/src/components/Select/Select.tsx +++ b/src/mantine-core/src/components/Select/Select.tsx @@ -214,6 +214,10 @@ export const Select = forwardRef( const isDeselectable = allowDeselect === undefined ? clearable : allowDeselect; const setDropdownOpened = (opened: boolean) => { + if (dropdownOpened === opened) { + return; + } + _setDropdownOpened(opened); const handler = opened ? onDropdownOpen : onDropdownClose; typeof handler === 'function' && handler(); From 9e8045f8e430043f8540a86ef65eba31b9f7e47d Mon Sep 17 00:00:00 2001 From: Wesley Moses Date: Sat, 19 Feb 2022 11:43:41 +0200 Subject: [PATCH 2/2] [@mantine/core] Select: do not use early return --- src/mantine-core/src/components/Select/Select.tsx | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/mantine-core/src/components/Select/Select.tsx b/src/mantine-core/src/components/Select/Select.tsx index 84a4cd8dcf2..29e0b1ca717 100644 --- a/src/mantine-core/src/components/Select/Select.tsx +++ b/src/mantine-core/src/components/Select/Select.tsx @@ -214,13 +214,11 @@ export const Select = forwardRef( const isDeselectable = allowDeselect === undefined ? clearable : allowDeselect; const setDropdownOpened = (opened: boolean) => { - if (dropdownOpened === opened) { - return; + if (dropdownOpened !== opened) { + _setDropdownOpened(opened); + const handler = opened ? onDropdownOpen : onDropdownClose; + typeof handler === 'function' && handler(); } - - _setDropdownOpened(opened); - const handler = opened ? onDropdownOpen : onDropdownClose; - typeof handler === 'function' && handler(); }; const isCreatable = creatable && typeof getCreateLabel === 'function';