svelte-multiselect 11.1.0 โ 11.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/CircleSpinner.svelte +2 -1
- package/dist/CmdPalette.svelte +13 -7
- package/dist/CmdPalette.svelte.d.ts +4 -5
- package/dist/CodeExample.svelte +80 -0
- package/dist/CodeExample.svelte.d.ts +22 -0
- package/dist/CopyButton.svelte +47 -0
- package/dist/CopyButton.svelte.d.ts +25 -0
- package/dist/FileDetails.svelte +53 -0
- package/dist/FileDetails.svelte.d.ts +21 -0
- package/dist/GitHubCorner.svelte +82 -0
- package/dist/GitHubCorner.svelte.d.ts +13 -0
- package/dist/Icon.svelte +23 -0
- package/dist/Icon.svelte.d.ts +8 -0
- package/dist/MultiSelect.svelte +128 -75
- package/dist/MultiSelect.svelte.d.ts +2 -3
- package/dist/PrevNext.svelte +100 -0
- package/dist/PrevNext.svelte.d.ts +48 -0
- package/dist/RadioButtons.svelte +67 -0
- package/dist/RadioButtons.svelte.d.ts +44 -0
- package/dist/Toggle.svelte +78 -0
- package/dist/Toggle.svelte.d.ts +16 -0
- package/dist/icons.d.ts +47 -0
- package/dist/icons.js +46 -0
- package/dist/index.d.ts +10 -3
- package/dist/index.js +10 -3
- package/dist/types.d.ts +141 -0
- package/dist/utils.d.ts +6 -22
- package/dist/utils.js +17 -25
- package/package.json +18 -37
- package/readme.md +287 -121
- package/dist/icons/ChevronExpand.svelte +0 -9
- package/dist/icons/ChevronExpand.svelte.d.ts +0 -4
- package/dist/icons/Cross.svelte +0 -10
- package/dist/icons/Cross.svelte.d.ts +0 -4
- package/dist/icons/Disabled.svelte +0 -10
- package/dist/icons/Disabled.svelte.d.ts +0 -4
- package/dist/icons/Octocat.svelte +0 -9
- package/dist/icons/Octocat.svelte.d.ts +0 -4
- package/dist/icons/index.d.ts +0 -4
- package/dist/icons/index.js +0 -4
- package/dist/props.d.ts +0 -143
- package/dist/props.js +0 -1
package/readme.md
CHANGED
|
@@ -36,9 +36,9 @@
|
|
|
36
36
|
|
|
37
37
|
## ๐งช   Coverage
|
|
38
38
|
|
|
39
|
-
| Statements | Branches
|
|
40
|
-
| ------------------------------------------------------------------------------------------ |
|
|
41
|
-
|  |  |  |
|
|
42
42
|
|
|
43
43
|
## ๐จ   Installation
|
|
44
44
|
|
|
@@ -66,334 +66,493 @@ Favorite Frontend Tools?
|
|
|
66
66
|
<MultiSelect bind:selected options={ui_libs} />
|
|
67
67
|
```
|
|
68
68
|
|
|
69
|
+
## ๐ง   Mental Model
|
|
70
|
+
|
|
71
|
+
| Prop | Purpose | Value |
|
|
72
|
+
| --------------- | ------------------------------------------------------ | ----------------------------------------------------------------------------------- |
|
|
73
|
+
| `options` | What users can choose from | Array of strings, numbers, or objects with `label` property |
|
|
74
|
+
| `bind:selected` | Which options users have chosen | Always an array: `[]`, `['Apple']` or `['Apple', 'Banana']` |
|
|
75
|
+
| `bind:value` | Single-select convenience for the user-selected option | Single item: `'Apple'` (or `null`) if `maxSelect={1}`, otherwise same as `selected` |
|
|
76
|
+
|
|
77
|
+
### Common Patterns
|
|
78
|
+
|
|
79
|
+
```svelte
|
|
80
|
+
<!-- Multi-select -->
|
|
81
|
+
<MultiSelect bind:selected options={['A', 'B', 'C']} />
|
|
82
|
+
|
|
83
|
+
<!-- Single-select -->
|
|
84
|
+
<MultiSelect bind:value options={colors} maxSelect={1} />
|
|
85
|
+
|
|
86
|
+
<!-- Object options (need 'label' property, can have arbitrary other keys, some like `value`, `disabled`, `preselected`, `style` have special meaning, see type ObjectOption) -->
|
|
87
|
+
<MultiSelect
|
|
88
|
+
bind:selected
|
|
89
|
+
options={[
|
|
90
|
+
{ label: 'Red', value: '#ff0000' },
|
|
91
|
+
{ label: 'Blue', value: '#0000ff' },
|
|
92
|
+
]}
|
|
93
|
+
/>
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### Troubleshooting
|
|
97
|
+
|
|
98
|
+
- **Object options not working?** โ Add `label` property
|
|
99
|
+
- **Dropdown not showing?** โ Check you have `options` and not `disabled={true}`
|
|
100
|
+
- **Want single item not array?** โ Use `bind:value` with `maxSelect={1}`
|
|
101
|
+
- **Types confusing?** โ Component auto-infers type of `selected` and `value` from your `options` array
|
|
102
|
+
|
|
69
103
|
## ๐ฃ   Props
|
|
70
104
|
|
|
71
|
-
|
|
105
|
+
Complete reference of all props. Props are organized by importance - **Essential Props** are what you'll use most often.
|
|
106
|
+
|
|
107
|
+
> **๐ก Tip:** The `Option` type is automatically inferred from your `options` array, or you can import it: `import { type Option } from 'svelte-multiselect'`
|
|
108
|
+
|
|
109
|
+
### Essential Props
|
|
110
|
+
|
|
111
|
+
These are the core props you'll use in most cases:
|
|
112
|
+
|
|
113
|
+
1. ```ts
|
|
114
|
+
options: Option[] // REQUIRED
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
**The only required prop.** Array of strings, numbers, or objects that users can select from. Objects must have a `label` property that will be displayed in the dropdown.
|
|
118
|
+
|
|
119
|
+
```svelte
|
|
120
|
+
<!-- Simple options -->
|
|
121
|
+
<MultiSelect options={['Red', 'Green', 'Blue']} />
|
|
122
|
+
|
|
123
|
+
<!-- Object options -->
|
|
124
|
+
<MultiSelect
|
|
125
|
+
options={[
|
|
126
|
+
{ label: 'Red', value: '#ff0000', hex: true },
|
|
127
|
+
{ label: 'Green', value: '#00ff00', hex: true },
|
|
128
|
+
]}
|
|
129
|
+
/>
|
|
130
|
+
```
|
|
72
131
|
|
|
73
132
|
1. ```ts
|
|
74
|
-
|
|
133
|
+
selected: Option[] = [] // bindable
|
|
75
134
|
```
|
|
76
135
|
|
|
77
|
-
|
|
136
|
+
**Your main state variable.** Array of currently selected options. Use `bind:selected` for two-way binding.
|
|
137
|
+
|
|
138
|
+
```svelte
|
|
139
|
+
<script>
|
|
140
|
+
let selected = $state(['Red']) // Pre-select Red
|
|
141
|
+
</script>
|
|
142
|
+
<MultiSelect bind:selected options={colors} />
|
|
143
|
+
```
|
|
78
144
|
|
|
79
145
|
1. ```ts
|
|
80
|
-
|
|
146
|
+
value: Option | Option[] | null = null // bindable
|
|
81
147
|
```
|
|
82
148
|
|
|
83
|
-
|
|
149
|
+
**Alternative to `selected`.** When `maxSelect={1}`, `value` is the single selected item (not an array). Otherwise, `value` equals `selected`.
|
|
150
|
+
|
|
151
|
+
```svelte
|
|
152
|
+
<!-- Single-select: value = 'Red' (not ['Red']) -->
|
|
153
|
+
<MultiSelect bind:value options={colors} maxSelect={1} />
|
|
154
|
+
|
|
155
|
+
<!-- Multi-select: value = ['Red', 'Blue'] (same as selected) -->
|
|
156
|
+
<MultiSelect bind:value options={colors} />
|
|
157
|
+
```
|
|
84
158
|
|
|
85
159
|
1. ```ts
|
|
86
|
-
|
|
160
|
+
maxSelect: number | null = null
|
|
87
161
|
```
|
|
88
162
|
|
|
89
|
-
|
|
163
|
+
**Controls selection behavior.** `null` = unlimited, `1` = single select, `2+` = limited multi-select.
|
|
164
|
+
|
|
165
|
+
```svelte
|
|
166
|
+
<!-- Unlimited selection -->
|
|
167
|
+
<MultiSelect options={colors} />
|
|
168
|
+
|
|
169
|
+
<!-- Single selection -->
|
|
170
|
+
<MultiSelect options={colors} maxSelect={1} />
|
|
171
|
+
|
|
172
|
+
<!-- Max 3 selections -->
|
|
173
|
+
<MultiSelect options={colors} maxSelect={3} />
|
|
174
|
+
```
|
|
90
175
|
|
|
91
176
|
1. ```ts
|
|
92
|
-
|
|
177
|
+
placeholder: string | null = null
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
Text shown when no options are selected.
|
|
181
|
+
|
|
182
|
+
1. ```ts
|
|
183
|
+
disabled: boolean = false
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
Disables the component. Users can't interact with it, but it's still rendered.
|
|
187
|
+
|
|
188
|
+
1. ```ts
|
|
189
|
+
required: boolean | number = false
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
For form validation. `true` means at least 1 option required, numbers specify exact minimum.
|
|
193
|
+
|
|
194
|
+
### Commonly Used Props
|
|
195
|
+
|
|
196
|
+
1. ```ts
|
|
197
|
+
searchText: string = `` // bindable
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
The text user entered to filter options. Bindable for external control.
|
|
201
|
+
|
|
202
|
+
1. ```ts
|
|
203
|
+
open: boolean = false // bindable
|
|
93
204
|
```
|
|
94
205
|
|
|
95
|
-
Whether
|
|
206
|
+
Whether the dropdown is visible. Bindable for external control.
|
|
96
207
|
|
|
97
208
|
1. ```ts
|
|
98
209
|
allowUserOptions: boolean | `append` = false
|
|
99
210
|
```
|
|
100
211
|
|
|
101
|
-
Whether users can
|
|
102
|
-
If `allowUserOptions` is `true` or `'append'` then the type `object | number | string` of entered value is determined by `typeof options[0]` (i.e. the first option in the dropdown list) to keep type homogeneity.
|
|
212
|
+
Whether users can create new options by typing. `true` = add to selected only, `'append'` = add to both options and selected.
|
|
103
213
|
|
|
104
214
|
1. ```ts
|
|
105
|
-
|
|
215
|
+
allowEmpty: boolean = false
|
|
106
216
|
```
|
|
107
217
|
|
|
108
|
-
|
|
218
|
+
Whether to allow the component to exist with no options. If `false`, shows console error when no options provided (unless `loading`, `disabled`, or `allowUserOptions` is `true`).
|
|
109
219
|
|
|
110
220
|
1. ```ts
|
|
111
|
-
|
|
221
|
+
loading: boolean = false
|
|
112
222
|
```
|
|
113
223
|
|
|
114
|
-
|
|
224
|
+
Shows a loading spinner. Useful when fetching options asynchronously.
|
|
115
225
|
|
|
116
226
|
1. ```ts
|
|
117
|
-
|
|
227
|
+
invalid: boolean = false // bindable
|
|
118
228
|
```
|
|
119
229
|
|
|
120
|
-
|
|
230
|
+
Marks the component as invalid (adds CSS class). Automatically set during form validation.
|
|
231
|
+
|
|
232
|
+
### Advanced Props
|
|
121
233
|
|
|
122
234
|
1. ```ts
|
|
123
|
-
|
|
235
|
+
activeIndex: number | null = null // bindable
|
|
124
236
|
```
|
|
125
237
|
|
|
126
|
-
|
|
238
|
+
Zero-based index of currently active option in the filtered list.
|
|
127
239
|
|
|
128
240
|
1. ```ts
|
|
129
|
-
|
|
241
|
+
activeOption: Option | null = null // bindable
|
|
130
242
|
```
|
|
131
243
|
|
|
132
|
-
|
|
244
|
+
Currently active option (hovered or navigated to with arrow keys).
|
|
133
245
|
|
|
134
246
|
1. ```ts
|
|
135
|
-
|
|
247
|
+
createOptionMsg: string | null = `Create this option...`
|
|
136
248
|
```
|
|
137
249
|
|
|
138
|
-
|
|
250
|
+
Message shown when `allowUserOptions` is enabled and user can create a new option.
|
|
139
251
|
|
|
140
252
|
1. ```ts
|
|
141
253
|
duplicates: boolean = false
|
|
142
254
|
```
|
|
143
255
|
|
|
144
|
-
Whether to allow
|
|
256
|
+
Whether to allow selecting the same option multiple times.
|
|
145
257
|
|
|
258
|
+
<!-- deno-fmt-ignore -->
|
|
146
259
|
1. ```ts
|
|
147
|
-
|
|
260
|
+
filterFunc: (opt: Option, searchText: string) => boolean
|
|
148
261
|
```
|
|
149
262
|
|
|
150
|
-
|
|
263
|
+
Custom function to filter options based on search text. Default filters by label.
|
|
151
264
|
|
|
152
|
-
<!--
|
|
265
|
+
<!-- deno-fmt-ignore -->
|
|
153
266
|
1. ```ts
|
|
154
|
-
key: (opt:
|
|
267
|
+
key: (opt: Option) => unknown
|
|
155
268
|
```
|
|
156
269
|
|
|
157
|
-
|
|
270
|
+
Function to determine option equality. Default compares by lowercased label.
|
|
158
271
|
|
|
159
272
|
1. ```ts
|
|
160
|
-
|
|
161
|
-
if (!searchText) return true
|
|
162
|
-
return `${get_label(opt)}`.toLowerCase().includes(searchText.toLowerCase())
|
|
163
|
-
}
|
|
273
|
+
closeDropdownOnSelect: boolean | 'if-mobile' | 'retain-focus' = 'if-mobile'
|
|
164
274
|
```
|
|
165
275
|
|
|
166
|
-
|
|
276
|
+
Whether to close dropdown after selection. `'if-mobile'` closes dropdown on mobile devices only (responsive). `'retain-focus'` closes dropdown but keeps input focused for rapid typing to create custom options from text input (see `allowUserOptions`).
|
|
167
277
|
|
|
168
278
|
1. ```ts
|
|
169
|
-
|
|
279
|
+
resetFilterOnAdd: boolean = true
|
|
170
280
|
```
|
|
171
281
|
|
|
172
|
-
|
|
282
|
+
Whether to clear search text when an option is selected.
|
|
173
283
|
|
|
174
284
|
1. ```ts
|
|
175
|
-
|
|
285
|
+
sortSelected: boolean | ((a: Option, b: Option) => number) = false
|
|
176
286
|
```
|
|
177
287
|
|
|
178
|
-
|
|
288
|
+
Whether/how to sort selected options. `true` uses default sort, function enables custom sorting.
|
|
179
289
|
|
|
180
290
|
1. ```ts
|
|
181
|
-
|
|
291
|
+
portal: { target_node?: HTMLElement; active?: boolean } = {}
|
|
182
292
|
```
|
|
183
293
|
|
|
184
|
-
|
|
294
|
+
Configuration for portal rendering. When `active: true`, the dropdown is rendered at document.body level with fixed positioning. Useful for avoiding z-index and overflow issues.
|
|
295
|
+
|
|
296
|
+
### Form & Accessibility Props
|
|
185
297
|
|
|
186
298
|
1. ```ts
|
|
187
299
|
id: string | null = null
|
|
188
300
|
```
|
|
189
301
|
|
|
190
|
-
Applied to the `<input>`
|
|
302
|
+
Applied to the `<input>` for associating with `<label>` elements.
|
|
303
|
+
|
|
304
|
+
1. ```ts
|
|
305
|
+
name: string | null = null
|
|
306
|
+
```
|
|
307
|
+
|
|
308
|
+
Form field name for form submission.
|
|
191
309
|
|
|
192
310
|
1. ```ts
|
|
193
|
-
|
|
311
|
+
autocomplete: string = 'off'
|
|
194
312
|
```
|
|
195
313
|
|
|
196
|
-
|
|
314
|
+
Browser autocomplete behavior. Usually `'on'` or `'off'`.
|
|
197
315
|
|
|
198
316
|
1. ```ts
|
|
199
317
|
inputmode: string | null = null
|
|
200
318
|
```
|
|
201
319
|
|
|
202
|
-
|
|
320
|
+
Hint for mobile keyboard type (`'numeric'`, `'tel'`, `'email'`, etc.). Set to `'none'` to hide keyboard.
|
|
203
321
|
|
|
204
322
|
1. ```ts
|
|
205
|
-
|
|
323
|
+
pattern: string | null = null
|
|
206
324
|
```
|
|
207
325
|
|
|
208
|
-
|
|
326
|
+
Regex pattern for input validation.
|
|
327
|
+
|
|
328
|
+
### UI & Behavior Props
|
|
209
329
|
|
|
210
330
|
1. ```ts
|
|
211
|
-
|
|
331
|
+
maxOptions: number | undefined = undefined
|
|
212
332
|
```
|
|
213
333
|
|
|
214
|
-
|
|
334
|
+
Limit number of options shown in dropdown. `undefined` = no limit.
|
|
215
335
|
|
|
216
336
|
1. ```ts
|
|
217
|
-
|
|
337
|
+
minSelect: number | null = null
|
|
218
338
|
```
|
|
219
339
|
|
|
220
|
-
|
|
340
|
+
Minimum selections required before remove buttons appear.
|
|
221
341
|
|
|
222
342
|
1. ```ts
|
|
223
|
-
|
|
343
|
+
autoScroll: boolean = true
|
|
224
344
|
```
|
|
225
345
|
|
|
226
|
-
|
|
346
|
+
Whether to keep active option in view when navigating with arrow keys.
|
|
227
347
|
|
|
228
348
|
1. ```ts
|
|
229
|
-
|
|
349
|
+
breakpoint: number = 800
|
|
230
350
|
```
|
|
231
351
|
|
|
232
|
-
|
|
352
|
+
Screen width (px) that separates 'mobile' from 'desktop' behavior.
|
|
233
353
|
|
|
234
354
|
1. ```ts
|
|
235
|
-
|
|
355
|
+
highlightMatches: boolean = true
|
|
236
356
|
```
|
|
237
357
|
|
|
238
|
-
|
|
358
|
+
Whether to highlight matching text in dropdown options.
|
|
239
359
|
|
|
240
360
|
1. ```ts
|
|
241
|
-
|
|
361
|
+
parseLabelsAsHtml: boolean = false
|
|
242
362
|
```
|
|
243
363
|
|
|
244
|
-
|
|
364
|
+
Whether to render option labels as HTML. **Warning:** Don't combine with `allowUserOptions` (XSS risk).
|
|
245
365
|
|
|
246
366
|
1. ```ts
|
|
247
|
-
|
|
367
|
+
selectedOptionsDraggable: boolean = !sortSelected
|
|
248
368
|
```
|
|
249
369
|
|
|
250
|
-
|
|
370
|
+
Whether selected options can be reordered by dragging.
|
|
371
|
+
|
|
372
|
+
### Message Props
|
|
251
373
|
|
|
252
374
|
1. ```ts
|
|
253
|
-
|
|
254
|
-
current: number,
|
|
255
|
-
max: number
|
|
256
|
-
) => (max > 1 ? `${current}/${max}` : ``)
|
|
375
|
+
noMatchingOptionsMsg: string = 'No matching options'
|
|
257
376
|
```
|
|
258
377
|
|
|
259
|
-
|
|
378
|
+
Message when search yields no results.
|
|
260
379
|
|
|
261
|
-
|
|
262
|
-
|
|
380
|
+
1. ```ts
|
|
381
|
+
duplicateOptionMsg: string = 'This option is already selected'
|
|
263
382
|
```
|
|
264
383
|
|
|
265
|
-
|
|
384
|
+
Message when user tries to create duplicate option.
|
|
266
385
|
|
|
267
386
|
1. ```ts
|
|
268
|
-
|
|
387
|
+
defaultDisabledTitle: string = 'This option is disabled'
|
|
269
388
|
```
|
|
270
389
|
|
|
271
|
-
|
|
390
|
+
Tooltip for disabled options.
|
|
391
|
+
|
|
392
|
+
1. ```ts
|
|
393
|
+
disabledInputTitle: string = 'This input is disabled'
|
|
394
|
+
```
|
|
272
395
|
|
|
273
|
-
|
|
396
|
+
Tooltip when component is disabled.
|
|
274
397
|
|
|
275
398
|
1. ```ts
|
|
276
|
-
|
|
399
|
+
removeAllTitle: string = 'Remove all'
|
|
277
400
|
```
|
|
278
401
|
|
|
279
|
-
|
|
402
|
+
Tooltip for remove-all button.
|
|
280
403
|
|
|
281
404
|
1. ```ts
|
|
282
|
-
|
|
405
|
+
removeBtnTitle: string = 'Remove'
|
|
283
406
|
```
|
|
284
407
|
|
|
285
|
-
|
|
408
|
+
Tooltip for individual remove buttons.
|
|
286
409
|
|
|
410
|
+
<!-- deno-fmt-ignore -->
|
|
287
411
|
1. ```ts
|
|
288
|
-
|
|
412
|
+
maxSelectMsg: ((current: number, max: number) => string) | null
|
|
289
413
|
```
|
|
290
414
|
|
|
291
|
-
|
|
415
|
+
Function to generate "X of Y selected" message. `null` = no message.
|
|
416
|
+
|
|
417
|
+
### DOM Element References (bindable)
|
|
418
|
+
|
|
419
|
+
These give you access to DOM elements after the component mounts:
|
|
292
420
|
|
|
293
421
|
1. ```ts
|
|
294
|
-
|
|
422
|
+
input: HTMLInputElement | null = null // bindable
|
|
295
423
|
```
|
|
296
424
|
|
|
297
|
-
|
|
425
|
+
Handle to the main `<input>` DOM element.
|
|
298
426
|
|
|
299
427
|
1. ```ts
|
|
300
|
-
|
|
428
|
+
form_input: HTMLInputElement | null = null // bindable
|
|
301
429
|
```
|
|
302
430
|
|
|
303
|
-
Handle to
|
|
431
|
+
Handle to the hidden form input used for validation.
|
|
304
432
|
|
|
305
433
|
1. ```ts
|
|
306
|
-
|
|
434
|
+
outerDiv: HTMLDivElement | null = null // bindable
|
|
307
435
|
```
|
|
308
436
|
|
|
309
|
-
|
|
437
|
+
Handle to the outer wrapper `<div>` element.
|
|
438
|
+
|
|
439
|
+
### Styling Props
|
|
440
|
+
|
|
441
|
+
For custom styling with CSS frameworks or one-off styles:
|
|
310
442
|
|
|
311
443
|
1. ```ts
|
|
312
|
-
|
|
444
|
+
style: string | null = null
|
|
313
445
|
```
|
|
314
446
|
|
|
315
|
-
|
|
447
|
+
CSS rules for the outer wrapper div.
|
|
316
448
|
|
|
317
449
|
1. ```ts
|
|
318
|
-
|
|
450
|
+
inputStyle: string | null = null
|
|
451
|
+
```
|
|
452
|
+
|
|
453
|
+
CSS rules for the main input element.
|
|
454
|
+
|
|
455
|
+
1. ```ts
|
|
456
|
+
ulSelectedStyle: string | null = null
|
|
319
457
|
```
|
|
320
458
|
|
|
321
|
-
|
|
459
|
+
CSS rules for the selected options list.
|
|
322
460
|
|
|
323
461
|
1. ```ts
|
|
324
|
-
|
|
462
|
+
ulOptionsStyle: string | null = null
|
|
325
463
|
```
|
|
326
464
|
|
|
327
|
-
|
|
465
|
+
CSS rules for the dropdown options list.
|
|
328
466
|
|
|
329
467
|
1. ```ts
|
|
330
|
-
|
|
468
|
+
liSelectedStyle: string | null = null
|
|
331
469
|
```
|
|
332
470
|
|
|
333
|
-
|
|
471
|
+
CSS rules for selected option list items.
|
|
334
472
|
|
|
335
473
|
1. ```ts
|
|
336
|
-
|
|
474
|
+
liOptionStyle: string | null = null
|
|
337
475
|
```
|
|
338
476
|
|
|
339
|
-
|
|
477
|
+
CSS rules for dropdown option list items.
|
|
478
|
+
|
|
479
|
+
### CSS Class Props
|
|
480
|
+
|
|
481
|
+
For use with CSS frameworks like Tailwind:
|
|
340
482
|
|
|
341
483
|
1. ```ts
|
|
342
|
-
|
|
484
|
+
outerDivClass: string = ''
|
|
343
485
|
```
|
|
344
486
|
|
|
345
|
-
|
|
487
|
+
CSS class for outer wrapper div.
|
|
346
488
|
|
|
347
489
|
1. ```ts
|
|
348
|
-
|
|
490
|
+
inputClass: string = ''
|
|
349
491
|
```
|
|
350
492
|
|
|
351
|
-
|
|
493
|
+
CSS class for main input element.
|
|
352
494
|
|
|
353
495
|
1. ```ts
|
|
354
|
-
|
|
355
|
-
options
|
|
356
|
-
?.filter((op) => (op as ObjectOption)?.preselected)
|
|
357
|
-
.slice(0, maxSelect ?? undefined) ?? []
|
|
496
|
+
ulSelectedClass: string = ''
|
|
358
497
|
```
|
|
359
498
|
|
|
360
|
-
|
|
499
|
+
CSS class for selected options list.
|
|
361
500
|
|
|
362
501
|
1. ```ts
|
|
363
|
-
|
|
502
|
+
ulOptionsClass: string = ''
|
|
364
503
|
```
|
|
365
504
|
|
|
366
|
-
|
|
505
|
+
CSS class for dropdown options list.
|
|
367
506
|
|
|
368
507
|
1. ```ts
|
|
369
|
-
|
|
508
|
+
liSelectedClass: string = ''
|
|
370
509
|
```
|
|
371
510
|
|
|
372
|
-
|
|
511
|
+
CSS class for selected option items.
|
|
373
512
|
|
|
374
513
|
1. ```ts
|
|
375
|
-
|
|
514
|
+
liOptionClass: string = ''
|
|
376
515
|
```
|
|
377
516
|
|
|
378
|
-
|
|
517
|
+
CSS class for dropdown option items.
|
|
379
518
|
|
|
380
519
|
1. ```ts
|
|
381
|
-
|
|
520
|
+
liActiveOptionClass: string = ''
|
|
382
521
|
```
|
|
383
522
|
|
|
384
|
-
|
|
523
|
+
CSS class for the currently active dropdown option.
|
|
385
524
|
|
|
386
525
|
1. ```ts
|
|
387
|
-
|
|
526
|
+
liUserMsgClass: string = ''
|
|
527
|
+
```
|
|
528
|
+
|
|
529
|
+
CSS class for user messages (no matches, create option, etc.).
|
|
530
|
+
|
|
531
|
+
1. ```ts
|
|
532
|
+
liActiveUserMsgClass: string = ''
|
|
388
533
|
```
|
|
389
534
|
|
|
390
|
-
|
|
535
|
+
CSS class for active user messages.
|
|
391
536
|
|
|
392
537
|
1. ```ts
|
|
393
|
-
|
|
538
|
+
maxSelectMsgClass: string = ''
|
|
394
539
|
```
|
|
395
540
|
|
|
396
|
-
|
|
541
|
+
CSS class for the "X of Y selected" message.
|
|
542
|
+
|
|
543
|
+
### Read-only Props (bindable)
|
|
544
|
+
|
|
545
|
+
These reflect internal component state:
|
|
546
|
+
|
|
547
|
+
1. ```ts
|
|
548
|
+
matchingOptions: Option[] = [] // bindable
|
|
549
|
+
```
|
|
550
|
+
|
|
551
|
+
Currently filtered options based on search text.
|
|
552
|
+
|
|
553
|
+
### Bindable Props
|
|
554
|
+
|
|
555
|
+
`selected`, `value`, `searchText`, `open`, `activeIndex`, `activeOption`, `invalid`, `input`, `outerDiv`, `form_input`, `options`, `matchingOptions`
|
|
397
556
|
|
|
398
557
|
## ๐ฐ   Snippets
|
|
399
558
|
|
|
@@ -416,10 +575,10 @@ Example using several snippets:
|
|
|
416
575
|
```svelte
|
|
417
576
|
<MultiSelect options={[`Red`, `Green`, `Blue`, `Yellow`, `Purple`]}>
|
|
418
577
|
{#snippet children({ idx, option })}
|
|
419
|
-
<span style="display: flex; align-items: center; gap: 6pt
|
|
578
|
+
<span style="display: flex; align-items: center; gap: 6pt">
|
|
420
579
|
<span
|
|
421
580
|
style:background={`${option}`}
|
|
422
|
-
style="border-radius: 50%; width: 1em; height: 1em
|
|
581
|
+
style="border-radius: 50%; width: 1em; height: 1em"
|
|
423
582
|
></span>
|
|
424
583
|
{idx + 1}
|
|
425
584
|
{option}
|
|
@@ -444,6 +603,12 @@ Example using several snippets:
|
|
|
444
603
|
|
|
445
604
|
Triggers when a new option is selected. The newly selected option is provided as `event.detail.option`.
|
|
446
605
|
|
|
606
|
+
1. ```ts
|
|
607
|
+
oncreate={(event) => console.log(event.detail.option)}
|
|
608
|
+
```
|
|
609
|
+
|
|
610
|
+
Triggers when a user creates a new option (when `allowUserOptions` is enabled). The created option is provided as `event.detail.option`.
|
|
611
|
+
|
|
447
612
|
1. ```ts
|
|
448
613
|
onremove={(event) => console.log(event.detail.option)}`
|
|
449
614
|
```
|
|
@@ -519,10 +684,10 @@ You can also import [the types this component uses](https://github.com/janosh/sv
|
|
|
519
684
|
|
|
520
685
|
```ts
|
|
521
686
|
import {
|
|
522
|
-
Option,
|
|
523
|
-
ObjectOption,
|
|
524
687
|
DispatchEvents,
|
|
525
688
|
MultiSelectEvents,
|
|
689
|
+
ObjectOption,
|
|
690
|
+
Option,
|
|
526
691
|
} from 'svelte-multiselect'
|
|
527
692
|
```
|
|
528
693
|
|
|
@@ -584,6 +749,7 @@ Minimal example that changes the background color of the options dropdown:
|
|
|
584
749
|
- `background: var(--sms-options-bg, white)`: Background of dropdown list.
|
|
585
750
|
- `max-height: var(--sms-options-max-height, 50vh)`: Maximum height of options dropdown.
|
|
586
751
|
- `overscroll-behavior: var(--sms-options-overscroll, none)`: Whether scroll events bubble to parent elements when reaching the top/bottom of the options dropdown. See [MDN](https://developer.mozilla.org/docs/Web/CSS/overscroll-behavior).
|
|
752
|
+
- `z-index: var(--sms-options-z-index, 3)`: Z-index for the dropdown options list.
|
|
587
753
|
- `box-shadow: var(--sms-options-shadow, 0 0 14pt -8pt black)`: Box shadow of dropdown list.
|
|
588
754
|
- `border: var(--sms-options-border)`
|
|
589
755
|
- `border-width: var(--sms-options-border-width)`
|