Skip to content

Commit f0d64fd

Browse files
authored
Fix TypeError: Cannot read properties of null (reading 'get_label') at MultiSelect.svelte:75 (#122)
* fix TypeError: Cannot read properties of null (reading 'get_label') at MultiSelect.svelte:75 * readme describe class names in section '### With CSS frameworks'
1 parent 8ab0d21 commit f0d64fd

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

readme.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ import type { Option } from 'svelte-multiselect'
220220
options: Option[]
221221
```
222222

223-
**The only required prop** (no default). Array of strings/numbers or `Option` objects to be listed in the dropdown. The only required key on objects is `label` which must also be unique. An object's `value` defaults to `label` if `undefined`. You can add arbitrary additional keys to your option objects. A few keys like `preselected` and `title` have special meaning though. See `src/lib/index.ts` for all special keys and their purpose.
223+
**The only required prop** (no default). Array of strings/numbers or `Option` objects to be listed in the dropdown. The only required key on objects is `label` which must also be unique. An object's `value` defaults to `label` if `undefined`. You can add arbitrary additional keys to your option objects. A few keys like `preselected` and `title` have special meaning though. See type `ObjectOption` in [`src/lib/index.ts`](https://github.com/janosh/svelte-multiselect/blob/main/src/lib/index.ts) for all special keys and their purpose.
224224

225225
1. ```ts
226226
outerDiv: HTMLDivElement | null = null
@@ -483,12 +483,12 @@ For example, to change the background color of the options dropdown:
483483
484484
The second method allows you to pass in custom classes to the important DOM elements of this component to target them with frameworks like [Tailwind CSS](https://tailwindcss.com).
485485
486-
- `outerDivClass`
487-
- `ulSelectedClass`
488-
- `liSelectedClass`
489-
- `ulOptionsClass`
490-
- `liOptionClass`
491-
- `liActiveOptionClass`
486+
- `outerDivClass`: wrapper `div` enclosing the whole component
487+
- `ulSelectedClass`: list of selected options
488+
- `liSelectedClass`: selected list items
489+
- `ulOptionsClass`: available options listed in the dropdown when component is in `open` state
490+
- `liOptionClass`: list items selectable from dropdown list
491+
- `liActiveOptionClass`: the currently active dropdown list item (i.e. hovered or navigated to with arrow keys)
492492
493493
This simplified version of the DOM structure of the component shows where these classes are inserted:
494494

src/lib/MultiSelect.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@
8181
let window_width: number
8282
8383
let wiggle = false // controls wiggle animation when user tries to exceed maxSelect
84-
$: selectedLabels = selected.map(get_label)
85-
$: selectedValues = selected.map(get_value)
84+
$: selectedLabels = selected?.map(get_label) ?? []
85+
$: selectedValues = selected?.map(get_value) ?? []
8686
8787
// formValue binds to input.form-control to prevent form submission if required
8888
// prop is true and no options are selected

tests/unit/multiselect.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ describe(`MultiSelect`, () => {
180180
})
181181

182182
// https://github.com/janosh/svelte-multiselect/issues/119
183-
test(`invokes callback function on keyup and keydown`, async () => {
183+
test(`invokes callback functions on input node DOM events`, async () => {
184184
const options = [1, 2, 3]
185185

186186
const events: [keyof MultiSelectEvents, Event][] = [

0 commit comments

Comments
 (0)