From 1425a6c22c4457933d60e4ab51f6b216e8a5120d Mon Sep 17 00:00:00 2001 From: Batuhan Tomo <91488737+Rekl0w@users.noreply.github.com> Date: Thu, 12 Sep 2024 14:27:59 +0300 Subject: [PATCH] Fix #7163: Refactor AutoComplete.js to fix the group selection (#7164) --- components/lib/autocomplete/AutoComplete.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/components/lib/autocomplete/AutoComplete.js b/components/lib/autocomplete/AutoComplete.js index 647b5b425c..e4a9c48ced 100644 --- a/components/lib/autocomplete/AutoComplete.js +++ b/components/lib/autocomplete/AutoComplete.js @@ -407,11 +407,16 @@ export const AutoComplete = React.memo( return; } - const inputValue = ObjectUtils.trim(event.target.value); - const item = (props.suggestions || []).find((it) => { + const inputValue = ObjectUtils.trim(event.target.value).toLowerCase(); + const allItems = (props.suggestions || []).flatMap((group) => { + return group.items ? group.items : [group]; + }); + + const item = allItems.find((it) => { const value = props.field ? ObjectUtils.resolveFieldData(it, props.field) : it; + const trimmedValue = value ? ObjectUtils.trim(value).toLowerCase() : ''; - return value && inputValue === ObjectUtils.trim(value); + return trimmedValue && inputValue === trimmedValue; }); if (item) {