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

fix: #7527, Dropdown: Editable Dropdown search not working as expected #7528

Merged
merged 1 commit into from
Dec 26, 2024

Conversation

akshayaqburst
Copy link
Contributor

fix: #7527, Dropdown: Editable Dropdown search not working as expected

#7527

Copy link

vercel bot commented Dec 26, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

2 Skipped Deployments
Name Status Preview Updated (UTC)
primereact ⬜️ Ignored (Inspect) Visit Preview Dec 26, 2024 8:37am
primereact-v9 ⬜️ Ignored (Inspect) Visit Preview Dec 26, 2024 8:37am

if (exactMatch !== -1) return exactMatch;

return visibleOptions.findIndex((item) => getOptionLabel(item).toLocaleLowerCase().startsWith(normalizedSearch));
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't this do it more efficientialy by only calling FindIndex 1 instead of passing over the whole array twice?

const search = (visibleOptions, searchText) => {
    if (!searchText || !visibleOptions?.length) return -1;

    const normalizedSearch = searchText.toLocaleLowerCase();

    return visibleOptions.findIndex((item) => {
        const label = getOptionLabel(item).toLocaleLowerCase();
        return label === normalizedSearch || label.startsWith(normalizedSearch);
    });
};

I would also call the method search instead of findInArray

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh no i see you want to search the whole list for an exact match before trying again with startswith

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, we will need to iterate the array twice in this case. Once to find the exact match and then to find matches with startsWith.

@melloware melloware merged commit fb4d9f1 into primefaces:master Dec 26, 2024
4 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Dropdown: Editable Dropdown search not working as expected.
2 participants