svelte-multiselect 8.0.0 → 8.0.2
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/MultiSelect.svelte +30 -165
- package/Wiggle.svelte +3 -3
- package/package.json +16 -16
- package/readme.md +16 -52
package/MultiSelect.svelte
CHANGED
|
@@ -301,7 +301,8 @@ function on_click_outside(event) {
|
|
|
301
301
|
<!-- bind:value={selected} prevents form submission if required prop is true and no options are selected -->
|
|
302
302
|
<input
|
|
303
303
|
{required}
|
|
304
|
-
|
|
304
|
+
{name}
|
|
305
|
+
value={selected.length > 0 ? JSON.stringify(selected) : null}
|
|
305
306
|
tabindex="-1"
|
|
306
307
|
aria-hidden="true"
|
|
307
308
|
aria-label="ignore this, used only to prevent form submission if select is required but empty"
|
|
@@ -344,7 +345,6 @@ function on_click_outside(event) {
|
|
|
344
345
|
on:focus
|
|
345
346
|
on:focus={open_dropdown}
|
|
346
347
|
{id}
|
|
347
|
-
{name}
|
|
348
348
|
{disabled}
|
|
349
349
|
{inputmode}
|
|
350
350
|
{pattern}
|
|
@@ -465,154 +465,17 @@ function on_click_outside(event) {
|
|
|
465
465
|
{/if}
|
|
466
466
|
</div>
|
|
467
467
|
|
|
468
|
-
<style
|
|
469
|
-
|
|
470
|
-
align-items: center;
|
|
471
|
-
display: flex;
|
|
472
|
-
cursor: text;
|
|
473
|
-
border: var(--sms-border, 1pt solid lightgray);
|
|
474
|
-
border-radius: var(--sms-border-radius, 3pt);
|
|
475
|
-
background: var(--sms-bg);
|
|
476
|
-
max-width: var(--sms-max-width);
|
|
477
|
-
padding: var(--sms-padding, 0 3pt);
|
|
478
|
-
color: var(--sms-text-color);
|
|
479
|
-
font-size: var(--sms-font-size, inherit);
|
|
480
|
-
min-height: var(--sms-min-height, 19pt);
|
|
481
|
-
margin: var(--sms-margin);
|
|
482
|
-
}
|
|
483
|
-
:where(div.multiselect).open {
|
|
484
|
-
/* increase z-index when open to ensure the dropdown of one <MultiSelect />
|
|
485
|
-
displays above that of another slightly below it on the page */
|
|
486
|
-
z-index: var(--sms-open-z-index, 4);
|
|
487
|
-
}
|
|
488
|
-
:where(div.multiselect):focus-within {
|
|
489
|
-
border: var(--sms-focus-border, 1pt solid var(--sms-active-color, cornflowerblue));
|
|
490
|
-
}
|
|
491
|
-
:where(div.multiselect).disabled {
|
|
492
|
-
background: var(--sms-disabled-bg, lightgray);
|
|
493
|
-
cursor: not-allowed;
|
|
494
|
-
}
|
|
495
|
-
:where(div.multiselect) > ul.selected {
|
|
496
|
-
display: flex;
|
|
497
|
-
flex: 1;
|
|
498
|
-
padding: 0;
|
|
499
|
-
margin: 0;
|
|
500
|
-
flex-wrap: wrap;
|
|
501
|
-
}
|
|
502
|
-
:where(div.multiselect) > ul.selected > li {
|
|
503
|
-
align-items: center;
|
|
504
|
-
border-radius: 3pt;
|
|
505
|
-
display: flex;
|
|
506
|
-
margin: 2pt;
|
|
507
|
-
line-height: normal;
|
|
508
|
-
transition: 0.3s;
|
|
509
|
-
white-space: nowrap;
|
|
510
|
-
background: var(--sms-selected-bg, rgba(0, 0, 0, 0.15));
|
|
511
|
-
padding: var(--sms-selected-li-padding, 1pt 5pt);
|
|
512
|
-
color: var(--sms-selected-text-color, var(--sms-text-color));
|
|
513
|
-
}
|
|
514
|
-
:where(div.multiselect) button {
|
|
515
|
-
border-radius: 50%;
|
|
516
|
-
display: flex;
|
|
517
|
-
transition: 0.2s;
|
|
518
|
-
color: inherit;
|
|
519
|
-
background: transparent;
|
|
520
|
-
border: none;
|
|
521
|
-
cursor: pointer;
|
|
522
|
-
outline: none;
|
|
523
|
-
padding: 0;
|
|
524
|
-
margin: 0 0 0 3pt; /* CSS reset */
|
|
525
|
-
}
|
|
526
|
-
:where(div.multiselect) button.remove-all {
|
|
527
|
-
margin: 0 3pt;
|
|
528
|
-
}
|
|
529
|
-
:where(div.multiselect) ul.selected > li button:hover,
|
|
530
|
-
:where(div.multiselect) button.remove-all:hover,
|
|
531
|
-
:where(div.multiselect) button:focus {
|
|
532
|
-
color: var(--sms-remove-btn-hover-color, lightskyblue);
|
|
533
|
-
background: var(--sms-remove-btn-hover-bg, rgba(0, 0, 0, 0.2));
|
|
534
|
-
}
|
|
535
|
-
:where(div.multiselect) input {
|
|
536
|
-
margin: auto 0; /* CSS reset */
|
|
537
|
-
padding: 0; /* CSS reset */
|
|
538
|
-
}
|
|
539
|
-
:where(div.multiselect) > ul.selected > li > input {
|
|
540
|
-
border: none;
|
|
541
|
-
outline: none;
|
|
542
|
-
background: none;
|
|
543
|
-
flex: 1; /* this + next line fix issue #12 https://git.io/JiDe3 */
|
|
544
|
-
min-width: 2em;
|
|
545
|
-
/* ensure input uses text color and not --sms-selected-text-color */
|
|
546
|
-
color: var(--sms-text-color);
|
|
547
|
-
font-size: inherit;
|
|
548
|
-
cursor: inherit; /* needed for disabled state */
|
|
549
|
-
border-radius: 0; /* reset ul.selected > li */
|
|
550
|
-
}
|
|
551
|
-
:where(div.multiselect) > ul.selected > li > input::placeholder {
|
|
552
|
-
padding-left: 5pt;
|
|
553
|
-
color: var(--sms-placeholder-color);
|
|
554
|
-
opacity: var(--sms-placeholder-opacity);
|
|
555
|
-
}
|
|
556
|
-
:where(div.multiselect) > input.form-control {
|
|
557
|
-
width: 2em;
|
|
558
|
-
position: absolute;
|
|
559
|
-
background: transparent;
|
|
560
|
-
border: none;
|
|
561
|
-
outline: none;
|
|
562
|
-
z-index: -1;
|
|
563
|
-
opacity: 0;
|
|
564
|
-
pointer-events: none;
|
|
565
|
-
}
|
|
566
|
-
:where(div.multiselect) > ul.options {
|
|
567
|
-
list-style: none;
|
|
568
|
-
padding: 4pt 0;
|
|
569
|
-
top: 100%;
|
|
570
|
-
left: 0;
|
|
571
|
-
width: 100%;
|
|
572
|
-
position: absolute;
|
|
573
|
-
border-radius: 1ex;
|
|
574
|
-
overflow: auto;
|
|
575
|
-
background: var(--sms-options-bg, white);
|
|
576
|
-
max-height: var(--sms-options-max-height, 50vh);
|
|
577
|
-
overscroll-behavior: var(--sms-options-overscroll, none);
|
|
578
|
-
box-shadow: var(--sms-options-shadow, 0 0 14pt -8pt black);
|
|
579
|
-
transition: all 0.2s;
|
|
580
|
-
}
|
|
581
|
-
:where(div.multiselect) > ul.options.hidden {
|
|
582
|
-
visibility: hidden;
|
|
583
|
-
opacity: 0;
|
|
584
|
-
transform: translateY(50px);
|
|
585
|
-
}
|
|
586
|
-
:where(div.multiselect) > ul.options > li {
|
|
587
|
-
padding: 3pt 2ex;
|
|
588
|
-
cursor: pointer;
|
|
589
|
-
scroll-margin: var(--sms-options-scroll-margin, 100px);
|
|
590
|
-
}
|
|
591
|
-
:where(div.multiselect) > ul.options span {
|
|
592
|
-
padding: 3pt 2ex;
|
|
593
|
-
}
|
|
594
|
-
:where(div.multiselect) > ul.options > li.selected {
|
|
595
|
-
background: var(--sms-li-selected-bg);
|
|
596
|
-
color: var(--sms-li-selected-color);
|
|
597
|
-
}
|
|
598
|
-
:where(div.multiselect) > ul.options > li.active {
|
|
599
|
-
background: var(--sms-li-active-bg, var(--sms-active-color, rgba(0, 0, 0, 0.15)));
|
|
600
|
-
}
|
|
601
|
-
:where(div.multiselect) > ul.options > li.disabled {
|
|
602
|
-
cursor: not-allowed;
|
|
603
|
-
background: var(--sms-li-disabled-bg, #f5f5f6);
|
|
604
|
-
color: var(--sms-li-disabled-text, #b8b8b8);
|
|
605
|
-
}
|
|
606
|
-
|
|
607
|
-
@supports not selector(:where(div.multiselect)) {
|
|
608
|
-
div.multiselect {
|
|
468
|
+
<style>
|
|
469
|
+
:where(div.multiselect) {
|
|
609
470
|
position: relative;
|
|
610
471
|
align-items: center;
|
|
611
472
|
display: flex;
|
|
612
473
|
cursor: text;
|
|
474
|
+
box-sizing: border-box;
|
|
613
475
|
border: var(--sms-border, 1pt solid lightgray);
|
|
614
476
|
border-radius: var(--sms-border-radius, 3pt);
|
|
615
477
|
background: var(--sms-bg);
|
|
478
|
+
width: var(--sms-width);
|
|
616
479
|
max-width: var(--sms-max-width);
|
|
617
480
|
padding: var(--sms-padding, 0 3pt);
|
|
618
481
|
color: var(--sms-text-color);
|
|
@@ -620,26 +483,27 @@ function on_click_outside(event) {
|
|
|
620
483
|
min-height: var(--sms-min-height, 19pt);
|
|
621
484
|
margin: var(--sms-margin);
|
|
622
485
|
}
|
|
623
|
-
div.multiselect.open {
|
|
486
|
+
:where(div.multiselect.open) {
|
|
624
487
|
/* increase z-index when open to ensure the dropdown of one <MultiSelect />
|
|
625
488
|
displays above that of another slightly below it on the page */
|
|
626
489
|
z-index: var(--sms-open-z-index, 4);
|
|
627
490
|
}
|
|
628
|
-
div.multiselect:focus-within {
|
|
491
|
+
:where(div.multiselect:focus-within) {
|
|
629
492
|
border: var(--sms-focus-border, 1pt solid var(--sms-active-color, cornflowerblue));
|
|
630
493
|
}
|
|
631
|
-
div.multiselect.disabled {
|
|
494
|
+
:where(div.multiselect.disabled) {
|
|
632
495
|
background: var(--sms-disabled-bg, lightgray);
|
|
633
496
|
cursor: not-allowed;
|
|
634
497
|
}
|
|
635
|
-
|
|
498
|
+
|
|
499
|
+
:where(div.multiselect > ul.selected) {
|
|
636
500
|
display: flex;
|
|
637
501
|
flex: 1;
|
|
638
502
|
padding: 0;
|
|
639
503
|
margin: 0;
|
|
640
504
|
flex-wrap: wrap;
|
|
641
505
|
}
|
|
642
|
-
div.multiselect > ul.selected > li {
|
|
506
|
+
:where(div.multiselect > ul.selected > li) {
|
|
643
507
|
align-items: center;
|
|
644
508
|
border-radius: 3pt;
|
|
645
509
|
display: flex;
|
|
@@ -651,7 +515,7 @@ function on_click_outside(event) {
|
|
|
651
515
|
padding: var(--sms-selected-li-padding, 1pt 5pt);
|
|
652
516
|
color: var(--sms-selected-text-color, var(--sms-text-color));
|
|
653
517
|
}
|
|
654
|
-
div.multiselect button {
|
|
518
|
+
:where(div.multiselect button) {
|
|
655
519
|
border-radius: 50%;
|
|
656
520
|
display: flex;
|
|
657
521
|
transition: 0.2s;
|
|
@@ -663,20 +527,19 @@ function on_click_outside(event) {
|
|
|
663
527
|
padding: 0;
|
|
664
528
|
margin: 0 0 0 3pt; /* CSS reset */
|
|
665
529
|
}
|
|
666
|
-
div.multiselect button.remove-all {
|
|
530
|
+
:where(div.multiselect button.remove-all) {
|
|
667
531
|
margin: 0 3pt;
|
|
668
532
|
}
|
|
669
|
-
|
|
670
|
-
div.multiselect button.remove-all:hover,
|
|
671
|
-
div.multiselect button:focus {
|
|
533
|
+
:where(ul.selected > li button:hover, button.remove-all:hover, button:focus) {
|
|
672
534
|
color: var(--sms-remove-btn-hover-color, lightskyblue);
|
|
673
535
|
background: var(--sms-remove-btn-hover-bg, rgba(0, 0, 0, 0.2));
|
|
674
536
|
}
|
|
675
|
-
|
|
537
|
+
|
|
538
|
+
:where(div.multiselect input) {
|
|
676
539
|
margin: auto 0; /* CSS reset */
|
|
677
540
|
padding: 0; /* CSS reset */
|
|
678
541
|
}
|
|
679
|
-
div.multiselect > ul.selected > li > input {
|
|
542
|
+
:where(div.multiselect > ul.selected > li > input) {
|
|
680
543
|
border: none;
|
|
681
544
|
outline: none;
|
|
682
545
|
background: none;
|
|
@@ -688,12 +551,12 @@ div.multiselect button:focus {
|
|
|
688
551
|
cursor: inherit; /* needed for disabled state */
|
|
689
552
|
border-radius: 0; /* reset ul.selected > li */
|
|
690
553
|
}
|
|
691
|
-
div.multiselect > ul.selected > li > input::placeholder {
|
|
554
|
+
:where(div.multiselect > ul.selected > li > input::placeholder) {
|
|
692
555
|
padding-left: 5pt;
|
|
693
556
|
color: var(--sms-placeholder-color);
|
|
694
557
|
opacity: var(--sms-placeholder-opacity);
|
|
695
558
|
}
|
|
696
|
-
div.multiselect > input.form-control {
|
|
559
|
+
:where(div.multiselect > input.form-control) {
|
|
697
560
|
width: 2em;
|
|
698
561
|
position: absolute;
|
|
699
562
|
background: transparent;
|
|
@@ -703,7 +566,8 @@ div.multiselect button:focus {
|
|
|
703
566
|
opacity: 0;
|
|
704
567
|
pointer-events: none;
|
|
705
568
|
}
|
|
706
|
-
|
|
569
|
+
|
|
570
|
+
:where(div.multiselect > ul.options) {
|
|
707
571
|
list-style: none;
|
|
708
572
|
padding: 4pt 0;
|
|
709
573
|
top: 100%;
|
|
@@ -718,29 +582,30 @@ div.multiselect button:focus {
|
|
|
718
582
|
box-shadow: var(--sms-options-shadow, 0 0 14pt -8pt black);
|
|
719
583
|
transition: all 0.2s;
|
|
720
584
|
}
|
|
721
|
-
div.multiselect > ul.options.hidden {
|
|
585
|
+
:where(div.multiselect > ul.options.hidden) {
|
|
722
586
|
visibility: hidden;
|
|
723
587
|
opacity: 0;
|
|
724
588
|
transform: translateY(50px);
|
|
725
589
|
}
|
|
726
|
-
div.multiselect > ul.options > li {
|
|
590
|
+
:where(div.multiselect > ul.options > li) {
|
|
727
591
|
padding: 3pt 2ex;
|
|
728
592
|
cursor: pointer;
|
|
729
593
|
scroll-margin: var(--sms-options-scroll-margin, 100px);
|
|
730
594
|
}
|
|
731
|
-
|
|
595
|
+
/* for noOptionsMsg */
|
|
596
|
+
:where(div.multiselect > ul.options span) {
|
|
732
597
|
padding: 3pt 2ex;
|
|
733
598
|
}
|
|
734
|
-
div.multiselect > ul.options > li.selected {
|
|
599
|
+
:where(div.multiselect > ul.options > li.selected) {
|
|
735
600
|
background: var(--sms-li-selected-bg);
|
|
736
601
|
color: var(--sms-li-selected-color);
|
|
737
602
|
}
|
|
738
|
-
div.multiselect > ul.options > li.active {
|
|
603
|
+
:where(div.multiselect > ul.options > li.active) {
|
|
739
604
|
background: var(--sms-li-active-bg, var(--sms-active-color, rgba(0, 0, 0, 0.15)));
|
|
740
605
|
}
|
|
741
|
-
div.multiselect > ul.options > li.disabled {
|
|
606
|
+
:where(div.multiselect > ul.options > li.disabled) {
|
|
742
607
|
cursor: not-allowed;
|
|
743
608
|
background: var(--sms-li-disabled-bg, #f5f5f6);
|
|
744
609
|
color: var(--sms-li-disabled-text, #b8b8b8);
|
|
745
610
|
}
|
|
746
|
-
|
|
611
|
+
</style>
|
package/Wiggle.svelte
CHANGED
|
@@ -9,9 +9,9 @@ export let dy = 0; // try 10
|
|
|
9
9
|
export let duration = 200;
|
|
10
10
|
export let stiffness = 0.05;
|
|
11
11
|
export let damping = 0.1;
|
|
12
|
-
let
|
|
13
|
-
let store = spring(
|
|
14
|
-
$: store.set(wiggle ? { scale, angle, dx, dy } :
|
|
12
|
+
let rest_state = { angle: 0, scale: 1, dx: 0, dy: 0 };
|
|
13
|
+
let store = spring(rest_state, { stiffness, damping });
|
|
14
|
+
$: store.set(wiggle ? { scale, angle, dx, dy } : rest_state);
|
|
15
15
|
$: if (wiggle)
|
|
16
16
|
setTimeout(() => (wiggle = false), duration);
|
|
17
17
|
</script>
|
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": "8.0.
|
|
8
|
+
"version": "8.0.2",
|
|
9
9
|
"type": "module",
|
|
10
10
|
"svelte": "index.js",
|
|
11
11
|
"main": "index.js",
|
|
@@ -13,32 +13,32 @@
|
|
|
13
13
|
"devDependencies": {
|
|
14
14
|
"@iconify/svelte": "^3.0.0",
|
|
15
15
|
"@playwright/test": "^1.27.1",
|
|
16
|
-
"@sveltejs/adapter-static": "
|
|
17
|
-
"@sveltejs/kit": "
|
|
18
|
-
"@sveltejs/package": "
|
|
19
|
-
"@sveltejs/vite-plugin-svelte": "^1.0
|
|
20
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
21
|
-
"@typescript-eslint/parser": "^5.
|
|
22
|
-
"eslint": "^8.
|
|
16
|
+
"@sveltejs/adapter-static": "1.0.0-next.48",
|
|
17
|
+
"@sveltejs/kit": "1.0.0-next.538",
|
|
18
|
+
"@sveltejs/package": "1.0.0-next.5",
|
|
19
|
+
"@sveltejs/vite-plugin-svelte": "^1.1.0",
|
|
20
|
+
"@typescript-eslint/eslint-plugin": "^5.42.1",
|
|
21
|
+
"@typescript-eslint/parser": "^5.42.1",
|
|
22
|
+
"eslint": "^8.27.0",
|
|
23
23
|
"eslint-plugin-svelte3": "^4.0.0",
|
|
24
24
|
"hastscript": "^7.1.0",
|
|
25
|
-
"
|
|
25
|
+
"highlight.js": "^11.6.0",
|
|
26
|
+
"jsdom": "^20.0.2",
|
|
26
27
|
"mdsvex": "^0.10.6",
|
|
27
28
|
"prettier": "^2.7.1",
|
|
28
29
|
"prettier-plugin-svelte": "^2.8.0",
|
|
29
30
|
"rehype-autolink-headings": "^6.1.1",
|
|
30
|
-
"rehype-slug": "^5.0
|
|
31
|
-
"sass": "^1.55.0",
|
|
31
|
+
"rehype-slug": "^5.1.0",
|
|
32
32
|
"svelte": "^3.52.0",
|
|
33
33
|
"svelte-check": "^2.9.2",
|
|
34
34
|
"svelte-github-corner": "^0.1.0",
|
|
35
|
-
"svelte-preprocess": "^4.10.
|
|
36
|
-
"svelte-toc": "^0.4.
|
|
35
|
+
"svelte-preprocess": "^4.10.7",
|
|
36
|
+
"svelte-toc": "^0.4.1",
|
|
37
37
|
"svelte2tsx": "^0.5.20",
|
|
38
|
-
"tslib": "^2.4.
|
|
38
|
+
"tslib": "^2.4.1",
|
|
39
39
|
"typescript": "^4.8.4",
|
|
40
|
-
"vite": "^3.
|
|
41
|
-
"vitest": "^0.
|
|
40
|
+
"vite": "^3.2.3",
|
|
41
|
+
"vitest": "^0.25.0"
|
|
42
42
|
},
|
|
43
43
|
"keywords": [
|
|
44
44
|
"svelte",
|
package/readme.md
CHANGED
|
@@ -14,10 +14,10 @@
|
|
|
14
14
|
|
|
15
15
|
</h4>
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
<a href="https://svelte-multiselect.netlify.app">View the docs</a>
|
|
20
|
-
</
|
|
17
|
+
<p align="center"><strong>
|
|
18
|
+
Keyboard-friendly, accessible and highly customizable multi-select component.
|
|
19
|
+
<a class="hide-in-docs" href="https://svelte-multiselect.netlify.app">View the docs</a>
|
|
20
|
+
</strong></p>
|
|
21
21
|
|
|
22
22
|
<slot name="examples" />
|
|
23
23
|
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
|
|
50
50
|
```sh
|
|
51
51
|
npm install -D svelte-multiselect
|
|
52
|
-
pnpm
|
|
52
|
+
pnpm add -D svelte-multiselect
|
|
53
53
|
yarn add -D svelte-multiselect
|
|
54
54
|
```
|
|
55
55
|
|
|
@@ -73,11 +73,7 @@ Favorite Frontend Frameworks?
|
|
|
73
73
|
|
|
74
74
|
## Props
|
|
75
75
|
|
|
76
|
-
Full list of props/bindable variables for this component.
|
|
77
|
-
|
|
78
|
-
```ts
|
|
79
|
-
import type { Option } from 'svelte-multiselect'
|
|
80
|
-
```
|
|
76
|
+
Full list of props/bindable variables for this component. The `Option` type you see below is defined in [`src/lib/index.ts`](https://github.com/janosh/svelte-multiselect/blob/main/src/lib/index.ts) and can be imported as `import { type Option } from 'svelte-multiselect'`.
|
|
81
77
|
|
|
82
78
|
1. ```ts
|
|
83
79
|
activeIndex: number | null = null
|
|
@@ -152,7 +148,7 @@ import type { Option } from 'svelte-multiselect'
|
|
|
152
148
|
duplicates: boolean = false
|
|
153
149
|
```
|
|
154
150
|
|
|
155
|
-
Whether to allow users to select duplicate options. Applies only to the selected item list, not the options dropdown. Keeping that free of duplicates is left to developer. The selected item list can have duplicates if `allowUserOptions` is truthy, `duplicates` is `
|
|
151
|
+
Whether to allow users to select duplicate options. Applies only to the selected item list, not the options dropdown. Keeping that free of duplicates is left to developer. The selected item list can have duplicates if `allowUserOptions` is truthy, `duplicates` is `true` and users create the same option multiple times. Use `duplicateOptionMsg` to customize the message shown to user if `duplicates` is `false` and users attempt this and `duplicateFunc` to customize when a pair of options is considered a duplicate.
|
|
156
152
|
|
|
157
153
|
1. ```ts
|
|
158
154
|
duplicateOptionMsg: string = `This option is already selected`
|
|
@@ -219,9 +215,9 @@ import type { Option } from 'svelte-multiselect'
|
|
|
219
215
|
|
|
220
216
|
1. ```ts
|
|
221
217
|
maxSelectMsg: ((current: number, max: number) => string) | null = (
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
218
|
+
current: number,
|
|
219
|
+
max: number
|
|
220
|
+
) => (max > 1 ? `${current}/${max}` : ``)
|
|
225
221
|
```
|
|
226
222
|
|
|
227
223
|
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:
|
|
@@ -234,7 +230,7 @@ import type { Option } from 'svelte-multiselect'
|
|
|
234
230
|
name: string | null = null
|
|
235
231
|
```
|
|
236
232
|
|
|
237
|
-
Applied to the `<input>` element. Sets the key of this field in a submitted form data object.
|
|
233
|
+
Applied to the `<input>` element. Sets the key of this field in a submitted form data object. See [form example](https://svelte-multiselect.netlify.app/form).
|
|
238
234
|
|
|
239
235
|
1. ```ts
|
|
240
236
|
noMatchingOptionsMsg: string = `No matching options`
|
|
@@ -429,7 +425,8 @@ TypeScript users can import the types used for internal type safety:
|
|
|
429
425
|
|
|
430
426
|
```svelte
|
|
431
427
|
<script lang="ts">
|
|
432
|
-
import MultiSelect
|
|
428
|
+
import MultiSelect from 'svelte-multiselect'
|
|
429
|
+
import type { Option, ObjectOption } from 'svelte-multiselect'
|
|
433
430
|
|
|
434
431
|
const myOptions: ObjectOption[] = [
|
|
435
432
|
{ label: 'foo', value: 42 },
|
|
@@ -468,6 +465,7 @@ If you only want to make small adjustments, you can pass the following CSS varia
|
|
|
468
465
|
- `background: var(--sms-bg)`
|
|
469
466
|
- `color: var(--sms-text-color)`
|
|
470
467
|
- `min-height: var(--sms-min-height, 19pt)`
|
|
468
|
+
- `width: var(--sms-width)`
|
|
471
469
|
- `max-width: var(--sms-max-width)`
|
|
472
470
|
- `margin: var(--sms-margin)`
|
|
473
471
|
- `font-size: var(--sms-font-size, inherit)`
|
|
@@ -588,40 +586,6 @@ Odd as it may seem, you get the most fine-grained control over the styling of ev
|
|
|
588
586
|
}
|
|
589
587
|
```
|
|
590
588
|
|
|
591
|
-
## Downstream testing
|
|
592
|
-
|
|
593
|
-
To test a Svelte component which imports `svelte-multiselect`, you need to configure your test runner to avoid [transpiling issues](https://github.com/janosh/svelte-multiselect/issues/48).
|
|
594
|
-
|
|
595
|
-
For Jest, exclude `svelte-multiselect` from `transformIgnorePatterns` in your `jest.config.json`:
|
|
596
|
-
|
|
597
|
-
```json
|
|
598
|
-
{
|
|
599
|
-
"transformIgnorePatterns": ["node_modules/?!(svelte-multiselect)"],
|
|
600
|
-
"transform": {
|
|
601
|
-
"^.+\\.[t|j]s?$": "esbuild-jest",
|
|
602
|
-
"^.+\\.svelte$": ["svelte-jester", { "preprocess": true }]
|
|
603
|
-
}
|
|
604
|
-
}
|
|
605
|
-
```
|
|
606
|
-
|
|
607
|
-
For Vitest, include `svelte-multiselect` in `deps.inline`:
|
|
608
|
-
|
|
609
|
-
```ts
|
|
610
|
-
// vite.config.ts
|
|
611
|
-
import { svelte } from '@sveltejs/vite-plugin-svelte'
|
|
612
|
-
|
|
613
|
-
export default {
|
|
614
|
-
plugins: [svelte({ hot: !process.env.VITEST })],
|
|
615
|
-
test: {
|
|
616
|
-
deps: {
|
|
617
|
-
inline: [/svelte-multiselect/],
|
|
618
|
-
},
|
|
619
|
-
},
|
|
620
|
-
}
|
|
621
|
-
```
|
|
622
|
-
|
|
623
|
-
Here's a [Stackblitz example](https://stackblitz.com/fork/github/davipon/test-svelte-multiselect?initialPath=__vitest__) that also uses [`vitest-svelte-kit`](https://github.com/nickbreaton/vitest-svelte-kit).
|
|
624
|
-
|
|
625
589
|
## Want to contribute?
|
|
626
590
|
|
|
627
591
|
To submit a PR, clone the repo, install dependencies and start the dev server to try out your changes.
|
|
@@ -629,6 +593,6 @@ To submit a PR, clone the repo, install dependencies and start the dev server to
|
|
|
629
593
|
```sh
|
|
630
594
|
git clone https://github.com/janosh/svelte-multiselect
|
|
631
595
|
cd svelte-multiselect
|
|
632
|
-
|
|
633
|
-
|
|
596
|
+
pnpm install
|
|
597
|
+
pnpm dev
|
|
634
598
|
```
|