svelte-multiselect 5.0.2 → 5.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.
@@ -10,6 +10,7 @@ export let maxSelectMsg = null;
10
10
  export let disabled = false;
11
11
  export let disabledTitle = `This field is disabled`;
12
12
  export let options;
13
+ export let matchingOptions = [];
13
14
  export let selected = [];
14
15
  export let selectedLabels = [];
15
16
  export let selectedValues = [];
@@ -68,6 +69,9 @@ $: matchingOptions = options.filter((op) => filterFunc(op, searchText) &&
68
69
  !(op instanceof Object && op.disabled) &&
69
70
  !selectedLabels.includes(get_label(op)) // remove already selected options from dropdown list
70
71
  );
72
+ // reset activeOption if it's no longer in the matchingOptions list
73
+ $: if (activeOption && !matchingOptions.includes(activeOption))
74
+ activeOption = null;
71
75
  // add an option to selected list
72
76
  function add(label) {
73
77
  if (maxSelect && maxSelect > 1 && selected.length >= maxSelect)
@@ -225,7 +229,7 @@ function remove_all() {
225
229
  selected = [];
226
230
  searchText = ``;
227
231
  }
228
- $: isSelected = (label) => selectedLabels.includes(label);
232
+ $: is_selected = (label) => selectedLabels.includes(label);
229
233
  const if_enter_or_space = (handler) => (event) => {
230
234
  if ([`Enter`, `Space`].includes(event.code)) {
231
235
  event.preventDefault();
@@ -348,10 +352,10 @@ const if_enter_or_space = (handler) => (event) => {
348
352
  <li
349
353
  on:mousedown|stopPropagation
350
354
  on:mouseup|stopPropagation={() => {
351
- if (!disabled) isSelected(label) ? remove(label) : add(label)
355
+ if (!disabled) is_selected(label) ? remove(label) : add(label)
352
356
  }}
353
- title={disabled ? disabledTitle : (isSelected(label) && selectedTitle) || title}
354
- class:selected={isSelected(label)}
357
+ title={disabled ? disabledTitle : (is_selected(label) && selectedTitle) || title}
358
+ class:selected={is_selected(label)}
355
359
  class:active
356
360
  class:disabled
357
361
  class="{liOptionClass} {active ? liActiveOptionClass : ``}"
@@ -1,5 +1,5 @@
1
1
  import { SvelteComponentTyped } from "svelte";
2
- import { CustomEvents, Option } from './';
2
+ import { MultiSelectEvents, Option } from './';
3
3
  declare const __propDef: {
4
4
  props: {
5
5
  searchText?: string | undefined;
@@ -9,6 +9,7 @@ declare const __propDef: {
9
9
  disabled?: boolean | undefined;
10
10
  disabledTitle?: string | undefined;
11
11
  options: Option[];
12
+ matchingOptions?: Option[] | undefined;
12
13
  selected?: Option[] | undefined;
13
14
  selectedLabels?: (string | number)[] | undefined;
14
15
  selectedValues?: unknown[] | undefined;
@@ -53,7 +54,7 @@ declare const __propDef: {
53
54
  };
54
55
  };
55
56
  getters: {};
56
- events: CustomEvents;
57
+ events: MultiSelectEvents;
57
58
  };
58
59
  export declare type MultiSelectProps = typeof __propDef.props;
59
60
  export declare type MultiSelectEvents = typeof __propDef.events;
package/index.d.ts CHANGED
@@ -28,7 +28,7 @@ export declare type DispatchEvents = {
28
28
  focus: undefined;
29
29
  blur: undefined;
30
30
  };
31
- export declare type CustomEvents = {
31
+ export declare type MultiSelectEvents = {
32
32
  [key in keyof DispatchEvents]: CustomEvent<DispatchEvents[key]>;
33
33
  };
34
34
  export declare const get_label: (op: Option) => string | number;
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": "5.0.2",
8
+ "version": "5.0.3",
9
9
  "type": "module",
10
10
  "svelte": "index.js",
11
11
  "main": "index.js",
package/readme.md CHANGED
@@ -35,11 +35,6 @@
35
35
 
36
36
  ## Recent breaking changes
37
37
 
38
- - v4.0.0 renamed the slots for customizing how selected options and dropdown list items are rendered:
39
-
40
- - old: `<slot name="renderOptions" />`, new: `<slot name="option" />`
41
- - old: `<slot name="renderSelected" />`, new: `<slot name="selected" />`
42
-
43
38
  - v4.0.1 renamed the `readonly` prop to `disabled` which now prevents all form or user interaction with this component including opening the dropdown list which was still possible before. See [#45](https://github.com/janosh/svelte-multiselect/issues/45) for details. The associated CSS class applied to the outer `div` was likewise renamed to `div.multiselect.{readonly=>disabled}`.
44
39
 
45
40
  - v4.0.3 CSS variables starting with `--sms-input-<attr>` were renamed to just `--sms-<attr>`. E.g. `--sms-input-min-height` is now `--sms-min-height`.
@@ -87,6 +82,7 @@ Full list of props/bindable variables for this component:
87
82
  | `selected` | `[]` | Array of currently selected options. Can be bound to `bind:selected={[1, 2, 3]}` to control component state externally or passed as prop to set pre-selected options that will already be populated when component mounts before any user interaction. |
88
83
  | `selectedLabels` | `[]` | Labels of currently selected options. Exposed just for convenience, equivalent to `selected.map(op => op.label)` when options are objects. If options are simple strings, `selected === selectedLabels`. Supports binding but is read-only, i.e. since this value is reactive to `selected`, you cannot control `selected` by changing `bind:selectedLabels`. |
89
84
  | `selectedValues` | `[]` | Values of currently selected options. Exposed just for convenience, equivalent to `selected.map(op => op.value)` when options are objects. If options are simple strings, `selected === selectedValues`. Supports binding but is read-only, i.e. since this value is reactive to `selected`, you cannot control `selected` by changing `bind:selectedValues`. |
85
+ | `matchingOptions` | `Option[]` | List of options currently displayed to the user. Same as `options` unless the user entered `searchText` in which case this array contains only those options for which `filterFunc = (op: Option, searchText: string) => boolean` returned `true` (see [exposed methods](#exposed-methods) below for details on `filterFunc`). |
90
86
  | `sortSelected` | `boolean \| ((op1, op2) => number)` | Default behavior is to render selected items in the order they were chosen. `sortSelected={true}` uses default JS array sorting. A compare function enables custom logic for sorting selected options. See the [`/sort-selected`](https://svelte-multiselect.netlify.app/sort-selected) example. |
91
87
  | `noOptionsMsg` | `'No matching options'` | What message to show if no options match the user-entered search string. |
92
88
  | `disabled` | `false` | Disable the component. It will still be rendered but users won't be able to interact with it. |
@@ -105,7 +101,7 @@ Full list of props/bindable variables for this component:
105
101
  | `removeBtnTitle` | `'Remove'` | Title text to display when user hovers over button (cross icon) to remove selected option. |
106
102
  | `removeAllTitle` | `'Remove all'` | Title text to display when user hovers over remove-all button. |
107
103
  | `defaultDisabledTitle` | `'This option is disabled'` | Title text to display when user hovers over a disabled option. Each option can override this through its `disabledTitle` attribute. |
108
- | `autocomplete` | `'off'` | Applied to the `<input>`. Specifies if browser is permitted to auto-fill this form field. See [MDN docs](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/autocomplete) for other admissible values. |
104
+ | `autocomplete` | `'off'` | 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. |
109
105
  | `invalid` | `false` | If `required=true` and user tries to submit but `selected = []` is empty, `invalid` is automatically set to `true` and CSS class `invalid` applied to the top-level `div.multiselect`. `invalid` class is removed again as soon as the user selects an option. `invalid` can also be controlled externally by binding to it `<MultiSelect bind:invalid />` and setting it to `true` based on outside events or custom validation. |
110
106
 
111
107
  </div>
@@ -250,7 +246,7 @@ If you only want to make small adjustments, you can pass the following CSS varia
250
246
  - `div.multiselect > ul.options`
251
247
  - `background: var(--sms-options-bg, white)`: Background of dropdown list.
252
248
  - `max-height: var(--sms-options-max-height, 50vh)`: Maximum height of options dropdown.
253
- - `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/en-US/docs/Web/CSS/overscroll-behavior).
249
+ - `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).
254
250
  - `box-shadow: var(--sms-options-shadow, 0 0 14pt -8pt black);`: Box shadow of dropdown list.
255
251
  - `div.multiselect > ul.options > li`
256
252
  - `scroll-margin: var(--sms-options-scroll-margin, 100px)`: Top/bottom margin to keep between dropdown list items and top/bottom screen edge when auto-scrolling list to keep items in view.