Skip to content

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

Merged
melloware merged 1 commit intoprimefaces:masterfrom
qburst:master
Dec 26, 2024
Merged

fix: #7527, Dropdown: Editable Dropdown search not working as expected#7528
melloware merged 1 commit intoprimefaces:masterfrom
qburst:master

Conversation

@akshayaqburst
Copy link
Contributor

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

#7527

@vercel
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
2 of 3 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

Comments