Skip to content

How to sort selected items to the top of the list for Async? #5640

Answered by sleslein
sleslein asked this question in Q&A
Discussion options

You must be logged in to vote

I think I figured out a work around for this buy sorting the selected values in the with a custom MenuList component. Another bonus of this solution is that it doesn't require wrapping the onChange in a custom handler to mutate the selected values. It merely updates the order the existing items are rendered.

Code Sandbox Example: https://codesandbox.io/s/react-select-async-sort-selected-working-ex3oug

Example Code

import React from "react";

import AsyncSelect from "react-select/async";
import Select, { components } from "react-select";
import { options as baseOptions } from "./options";

const filterOptions = (inputValue: string) => {
  return baseOptions.filter((i) =>
    i.label.toLowe…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@sleslein
Comment options

@june6723
Comment options

Answer selected by sleslein
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants