Giter Club home page Giter Club logo

Comments (5)

Lemonsity avatar Lemonsity commented on August 23, 2024

A temporary get-around would be to simply declare a variable of type Option[], and implement event functions (add, remove, removeAll...).
Instead of using bind, we can add/remove/clear the previously mentioned array by passing the functions to on:add, on:remove events. The array we declared would then have the .length property

However, I believe compare to svelte-select, the benefit of this package is its bind, so it would still be great if a solution could be found

from svelte-multiselect.

janosh avatar janosh commented on August 23, 2024

@Lemonsity Thanks for the bug report. Will diagnose this now. There is a much simpler workaround for the time being though: use optional chaining. selected?.length should cause you no trouble.

from svelte-multiselect.

janosh avatar janosh commented on August 23, 2024

The problem also disappears if you declare let selected = []; instead of let selected;. The 2nd is equivalent to let selected = undefined;.

This component can't do anything about selected not having a length property in that case until it mounts. So either you need to delay rendering <p>{selected.length}</p> until MultiSelect mounts or ensure yourself that selected always has a length attribute.

from svelte-multiselect.

janosh avatar janosh commented on August 23, 2024

PS: Using the code also reveals another issue, that the "charlie" option becomes undefined in the drop-down menu. I am not sure if I should open a different issue for that. Sorry I could not identify the cause of the issue and fix it.

That's because you have a typo:

  const data = [
    {label: "alpha", value: "a"}, 
    {label: "bravo", value: "b"}, 
-   {lable: "charlie", value: "c"},
+   {label: "charlie", value: "c"},
  ];

from svelte-multiselect.

Lemonsity avatar Lemonsity commented on August 23, 2024

Hi Janosh,

Thanks a lot for the help. Can confirm both optional chaining and initializing the value are valid solutions as of now. I would however recommend initializing with an empty array, as you can do selected[index] that way.

from svelte-multiselect.

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.