-
Notifications
You must be signed in to change notification settings - Fork 4.1k
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
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
Limiting number of options rendered in dropdown #4516
Comments
Greetings @h3rmanj and sorry for the late reply. I could be missing something but you should be able modify your MenuList component to handle this. const MenuList = ({ children, ...props }) => {
return (
<components.MenuList {...props}>
{Array.isArray(children)
? children.slice(0, props.selectProps?.maxOptions) /* Options */
: children /* NoOptionsLabel */
}
</components.MenuList>
);
};
<Select components={{ MenuList }} maxOptions={5} /> |
Thanks! That seems like a good solution to me. I do still think it needs to be "officially" addressed though. I know this is a common problem in projects in my company. Reading through #127 and other issues, it seems like something many devs run into as well. So if it's not going to be supported in a prop, I'd still like to see a suggested solution in the docs. I'll close my two PR's though since there is a major rewrite in progress. |
@ebonow thanks for your solution. While this works for limiting the number of options displayed, In the past, I solved this issue by limiting how many times Any plans (or ideas) to address this issue? |
@ebonow The solution works but it is inefficient, since all options will still be rendered, even though almost all of them are discarded. |
I simply used an async select (https://react-select.com/async) as a workaround to limit results. it works quite well and is efficient. However limiting the number of options displayed at a time would certainly be useful |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
Continuation of #126, which got closed when react-select moved from v1 (?).
There should be a way to limit the number of options that are rendered to avoid sluggish (at best, even with high-end PCs) behavior when dealing with large lists.
Example: https://codesandbox.io/s/react-codesandboxer-example-forked-sijty
The workaround posted in #126 (comment) no longer works, and this needs to be addressed again.
I've made a PR in #4515 (which is a spiritual successor to #2611, also closed due to being v1), that simply adds a prop to limit the amount of options rendered. That solution might be too simple though, but I'm creating a feature request so it can be discussed here.
This issue also addresses the root cause of #4504
The text was updated successfully, but these errors were encountered: