GithubHelp home page GithubHelp logo

Comments (1)

hsuanyi-chou avatar hsuanyi-chou commented on June 17, 2024 1

Try-and-error many times and I found it's related to cmdk.

You can provide a filter in Command and the creatable selector won't freeze.

return (
      <Command
        {...commandProps}
        onKeyDown={(e) => {
          handleKeyDown(e);
          commandProps?.onKeyDown?.(e);
        }}
        className={cn('overflow-visible bg-transparent', commandProps?.className)}
        shouldFilter={
          commandProps?.shouldFilter !== undefined ? commandProps.shouldFilter : !onSearch
        } // When onSearch is provided, we don't want to filter the options. You can still override it.
+        filter={(value, search) => {
+          return value.toLowerCase().includes(search.toLowerCase()) ? 1 : -1;
+        }}
      >

here is a fixed version if you want to fix it yourself.

or an easy way to fix it without modifying multipleSelector.tsx by giving prop:

const MultipleSelectorCreatable = () => {
  return (
    <div className="w-full px-10">
      <MultipleSelector
        defaultOptions={OPTIONS}
        placeholder="Type something that does not exist in dropdowns..."
        creatable
        emptyIndicator={
          <p className="text-center text-lg leading-10 text-gray-600 dark:text-gray-400">
            no results found.
          </p>
        }
+        commandProps={{
+          filter: (value, search) => {
+              return value.toLowerCase().includes(search.toLowerCase()) ? 1 : -1;  // write your own filtering logic.
+          },
+        }}
      />
    </div>
  );
};

An known issue:
The filtering logic value.toLowerCase().includes(search.toLowerCase()) ? 1 : -1; will cause CreatableItem disappear when typing a space in the end. For example: Hello , a space in the end and the CreatableItem disappeared.

but Hello my friend works fine.

Because the value in cmdk is trim() so that they won't match.

image image

from shadcn-ui-expansions.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.