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

renderSuggestions based on group #731

Open
ajay-pal1 opened this issue Feb 21, 2024 · 1 comment
Open

renderSuggestions based on group #731

ajay-pal1 opened this issue Feb 21, 2024 · 1 comment

Comments

@ajay-pal1
Copy link

Is there any way we can render the suggestions based on the group

@JefHellemansBlockbax
Copy link

For anyone reading this in the future, unfortunately there is no easy fix with just a prop, but I worked around it by passing this function as customSuggestionsContainer prop:

function renderSuggestions(children: ReactNode) {
    const ul = children as ReactElement;
    const suggestions = ul.props.children as ReactElement[];
    // groupBy is a helper function from lodash
    const groupedSuggestions = groupBy(suggestions, suggestion => suggestion.props.suggestion.group);
    return (
        <div className="suggestionList">
            {Object.entries(groupedSuggestions).map(([group, suggestions]) =>
                cloneElement(ul, { ...ul.props, key: group }, [
                    <li key={group} className="suggestionGroup">
                        {group}
                    </li>,
                    ...suggestions
                ])
            )}
        </div>
    );
}

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

No branches or pull requests

2 participants