Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[@mantine/core] Select: fixed the display of values in the dropdown i… #3070

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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