svelte-multiselect 6.0.2 → 6.0.3

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.
@@ -37,7 +37,7 @@ export let options;
37
37
  export let outerDiv = null;
38
38
  export let outerDivClass = ``;
39
39
  export let parseLabelsAsHtml = false; // should not be combined with allowUserOptions!
40
- export let placeholder = undefined;
40
+ export let placeholder = null;
41
41
  export let removeAllTitle = `Remove all`;
42
42
  export let removeBtnTitle = `Remove`;
43
43
  export let required = false;
@@ -67,7 +67,7 @@ if (!Array.isArray(selected)) {
67
67
  console.error(`selected prop must be an array, got ${selected}`);
68
68
  }
69
69
  const dispatch = createEventDispatcher();
70
- let activeMsg = false; // controls active state of <li>{addOptionMsg}</li>
70
+ let add_option_msg_is_active = false; // controls active state of <li>{addOptionMsg}</li>
71
71
  let window_width;
72
72
  let wiggle = false; // controls wiggle animation when user tries to exceed maxSelect
73
73
  $: selectedLabels = selected.map(get_label);
@@ -205,34 +205,26 @@ async function handle_keydown(event) {
205
205
  // on up/down arrow keys: update active option
206
206
  else if ([`ArrowDown`, `ArrowUp`].includes(event.key)) {
207
207
  // if no option is active yet, but there are matching options, make first one active
208
- if (activeOption === null && matchingOptions.length > 0) {
209
- activeOption = matchingOptions[0];
208
+ if (activeIndex === null && matchingOptions.length > 0) {
209
+ activeIndex = 0;
210
210
  return;
211
211
  }
212
212
  else if (allowUserOptions && searchText.length > 0) {
213
213
  // if allowUserOptions is truthy and user entered text but no options match, we make
214
214
  // <li>{addUserMsg}</li> active on keydown (or toggle it if already active)
215
- activeMsg = !activeMsg;
215
+ add_option_msg_is_active = !add_option_msg_is_active;
216
216
  return;
217
217
  }
218
- else if (activeOption === null) {
218
+ else if (activeIndex === null) {
219
219
  // if no option is active and no options are matching, do nothing
220
220
  return;
221
221
  }
222
222
  const increment = event.key === `ArrowUp` ? -1 : 1;
223
- const newActiveIdx = matchingOptions.indexOf(activeOption) + increment;
224
- if (newActiveIdx < 0) {
225
- // wrap around top
226
- activeOption = matchingOptions[matchingOptions.length - 1];
227
- }
228
- else if (newActiveIdx === matchingOptions.length) {
229
- // wrap around bottom
230
- activeOption = matchingOptions[0];
231
- }
232
- else {
233
- // default case: select next/previous in item list
234
- activeOption = matchingOptions[newActiveIdx];
235
- }
223
+ activeIndex = (activeIndex + increment) % matchingOptions.length;
224
+ // % in JS behaves like remainder operator, not real modulo, so negative numbers stay negative
225
+ // need to do manual wrap around at 0
226
+ if (activeIndex < 0)
227
+ activeIndex = matchingOptions.length - 1;
236
228
  if (autoScroll) {
237
229
  // TODO This ugly timeout hack is needed to properly scroll element into view when wrapping
238
230
  // around start/end of option list. Find a better solution than waiting 10 ms to.
@@ -417,11 +409,11 @@ function on_click_outside(event) {
417
409
  on:mousedown|stopPropagation
418
410
  on:mouseup|stopPropagation={() => add(searchText)}
419
411
  title={addOptionMsg}
420
- class:active={activeMsg}
421
- on:mouseover={() => (activeMsg = true)}
422
- on:focus={() => (activeMsg = true)}
423
- on:mouseout={() => (activeMsg = false)}
424
- on:blur={() => (activeMsg = false)}
412
+ class:active={add_option_msg_is_active}
413
+ on:mouseover={() => (add_option_msg_is_active = true)}
414
+ on:focus={() => (add_option_msg_is_active = true)}
415
+ on:mouseout={() => (add_option_msg_is_active = false)}
416
+ on:blur={() => (add_option_msg_is_active = false)}
425
417
  aria-selected="false"
426
418
  >
427
419
  {addOptionMsg}
@@ -32,7 +32,7 @@ declare const __propDef: {
32
32
  outerDiv?: HTMLDivElement | null | undefined;
33
33
  outerDivClass?: string | undefined;
34
34
  parseLabelsAsHtml?: boolean | undefined;
35
- placeholder?: string | undefined;
35
+ placeholder?: string | null | undefined;
36
36
  removeAllTitle?: string | undefined;
37
37
  removeBtnTitle?: string | undefined;
38
38
  required?: boolean | undefined;
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "homepage": "https://svelte-multiselect.netlify.app",
6
6
  "repository": "https://github.com/janosh/svelte-multiselect",
7
7
  "license": "MIT",
8
- "version": "6.0.2",
8
+ "version": "6.0.3",
9
9
  "type": "module",
10
10
  "svelte": "index.js",
11
11
  "main": "index.js",
package/readme.md CHANGED
@@ -76,7 +76,7 @@ import type { Option } from 'svelte-multiselect'
76
76
  ```
77
77
 
78
78
  1. ```ts
79
- activeIndex: integer | null = null
79
+ activeIndex: number | null = null
80
80
  ```
81
81
 
82
82
  Zero-based index of currently active option in the array of currently matching options, i.e. if the user typed a search string into the input and only a subset of options match, this index refers to the array position of the matching subset of options
@@ -88,22 +88,22 @@ import type { Option } from 'svelte-multiselect'
88
88
  Currently active option, i.e. the one the user currently hovers or navigated to with arrow keys.
89
89
 
90
90
  1. ```ts
91
- addOptionMsg: string = 'Create this option...'
91
+ addOptionMsg: string = `Create this option...`
92
92
  ```
93
93
 
94
94
  Message shown to users after entering text when no options match their query and `allowUserOptions` is truthy.
95
95
 
96
96
  1. ```ts
97
- allowUserOptions: boolean = false
97
+ allowUserOptions: boolean | 'append' = false
98
98
  ```
99
99
 
100
100
  Whether users are allowed to enter values not in the dropdown list. `true` means add user-defined options to the selected list only, `'append'` means add to both options and selected.
101
101
 
102
102
  1. ```ts
103
- autocomplete: string = 'off'
103
+ autocomplete: string = `off`
104
104
  ```
105
105
 
106
- Applied to the `<input>`. Specifies if browser is permitted to auto-fill this form field. See [MDN docs](https://developer.mozilla.org/docs/Web/HTML/Attributes/autocomplete) for other admissible values.
106
+ Applied to the `<input>`. Specifies if browser is permitted to auto-fill this form field. Should usually be one of `'on'` or `'off'` but see [MDN docs](https://developer.mozilla.org/docs/Web/HTML/Attributes/autocomplete) for other admissible values.
107
107
 
108
108
  1. ```ts
109
109
  autoScroll: boolean = true
@@ -112,13 +112,13 @@ import type { Option } from 'svelte-multiselect'
112
112
  `false` disables keeping the active dropdown items in view when going up/down the list of options with arrow keys.
113
113
 
114
114
  1. ```ts
115
- breakpoint: integer = 800
115
+ breakpoint: number = 800
116
116
  ```
117
117
 
118
118
  Screens wider than `breakpoint` in pixels will be considered `'desktop'`, everything narrower as `'mobile'`.
119
119
 
120
120
  1. ```ts
121
- defaultDisabledTitle: string = 'This option is disabled'
121
+ defaultDisabledTitle: string = `This option is disabled`
122
122
  ```
123
123
 
124
124
  Title text to display when user hovers over a disabled option. Each option can override this through its `disabledTitle` attribute.
@@ -130,13 +130,13 @@ import type { Option } from 'svelte-multiselect'
130
130
  Disable the component. It will still be rendered but users won't be able to interact with it.
131
131
 
132
132
  1. ```ts
133
- disabledInputTitle: string = 'This input is disabled'
133
+ disabledInputTitle: string = `This input is disabled`
134
134
  ```
135
135
 
136
136
  Tooltip text to display on hover when the component is in `disabled` state.
137
137
 
138
138
  1. ```ts
139
- filterFunc: = (op: Option, searchText: string): boolean => {
139
+ filterFunc = (op: Option, searchText: string): boolean => {
140
140
  if (!searchText) return true
141
141
  return `${get_label(op)}`.toLowerCase().includes(searchText.toLowerCase())
142
142
  }
@@ -187,7 +187,7 @@ import type { Option } from 'svelte-multiselect'
187
187
  Positive integer to limit the number of options users can pick. `null` means no limit.
188
188
 
189
189
  1. ```ts
190
- maxSelectMsg: (current: number, max: number): string = null
190
+ maxSelectMsg: ((current: number, max: number) => string) | null = null
191
191
  ```
192
192
 
193
193
  Inform users how many of the maximum allowed options they have already selected. Set `maxSelectMsg={null}` to not show a message. Defaults to `null` when `maxSelect={1}` or `maxSelect={null}`. Else if `maxSelect > 1`, defaults to:
@@ -203,7 +203,7 @@ import type { Option } from 'svelte-multiselect'
203
203
  Applied to the `<input>` element. Sets the key of this field in a submitted form data object. Not useful at the moment since the value is stored in Svelte state, not on the `<input>` node.
204
204
 
205
205
  1. ```ts
206
- noOptionsMsg: string = 'No matching options'
206
+ noOptionsMsg: string = `No matching options`
207
207
  ```
208
208
 
209
209
  What message to show if no options match the user-entered search string.
@@ -239,13 +239,13 @@ import type { Option } from 'svelte-multiselect'
239
239
  String shown in the text input when no option is selected.
240
240
 
241
241
  1. ```ts
242
- removeAllTitle: string = 'Remove all'
242
+ removeAllTitle: string = `Remove all`
243
243
  ```
244
244
 
245
245
  Title text to display when user hovers over remove-all button.
246
246
 
247
247
  1. ```ts
248
- removeBtnTitle: string = 'Remove'
248
+ removeBtnTitle: string = `Remove`
249
249
  ```
250
250
 
251
251
  Title text to display when user hovers over button to remove selected option (which defaults to a cross icon).
@@ -257,7 +257,7 @@ import type { Option } from 'svelte-multiselect'
257
257
  Whether forms can be submitted without selecting any options. Aborts submission, is scrolled into view and shows help "Please fill out" message when true and user tries to submit with no options selected.
258
258
 
259
259
  1. ```ts
260
- searchText: string = ''
260
+ searchText: string = ``
261
261
  ```
262
262
 
263
263
  Text the user-entered to filter down on the list of options. Binds both ways, i.e. can also be used to set the input text.