Skip to content

Commit

Permalink
[@mantine/core] Select: Fix limit prop not working when current val…
Browse files Browse the repository at this point in the history
…ue matches one of the items from `data` (#3070)

* [@mantine/core] Select: fixed the display of values in the dropdown if the prop limit is passed

* [@mantine/core] Select: fixed the display of values in the dropdown if the prop limit is passed

* [@mantine/core] Select: run prettier

Co-authored-by: Denis.Yuhno <Denis.Yuhno@life.com.by>
  • Loading branch information
cheechoo28 and Denis.Yuhno committed Dec 4, 2022
1 parent 440b2e0 commit f729437
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/mantine-core/src/Select/filter-data/filter-data.ts
Expand Up @@ -26,6 +26,18 @@ export function filterData({
const selected = value != null ? data.find((item) => item.value === value) || null : null;

if (selected && !filterDataOnExactSearchMatch && selected?.label === searchValue) {
if (limit) {
if (limit >= data.length) {
return data;
}
const firstIndex = data.indexOf(selected);
const lastIndex = firstIndex + limit;
const firstIndexOffset = lastIndex - data.length;
if (firstIndexOffset > 0) {
return data.slice(firstIndex - firstIndexOffset);
}
return data.slice(firstIndex, lastIndex);
}
return data;
}

Expand Down

0 comments on commit f729437

Please sign in to comment.