Comments (5)
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.
@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.
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.
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.
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)
- Change liSelectedClass background color for each option HOT 1
- When allowUserOptions={true} user can't enter custom option if it is a substring of an existing option HOT 2
- Can't force svelte-multiselect box to not grow HOT 9
- Request textDocument/hover failed. Code: -32603 HOT 3
- CSS framework styles are overriden HOT 3
- Can't resolve './types' HOT 11
- The where classes are overwriting the classes I am giving through props. HOT 2
- Fire specific event if `allowUserOptions` was used to create a new option HOT 1
- Close dropdown after selecting option HOT 7
- on:removeAll returns empty array HOT 1
- Hiding dropdown while retaining focus on input, and having a placeholder after first selection
- How to make added values only as string with allowUserOptions? HOT 3
- Customizing user message <li> HOT 1
- Change event that doesn't conform to type HOT 2
- Tailwind css dark mode classes not picked up when passed as props. HOT 2
- Svelte 5 support? HOT 1
- Required doesn't reset when input has been invalidated HOT 1
- Typescript - Error: Property 'value' does not exist on type 'Option'. Did you mean 'valueOf'? HOT 6
- Options background not changing color in dark mode HOT 3
- Options not showing after calling focus on input HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from svelte-multiselect.