Skip to content

Commit 9159b20

Browse files
authored
Merge pull request #224 from iceljc/features/refine-chat-window
refine multiselect
2 parents 88bf3c9 + 1a91da2 commit 9159b20

File tree

2 files changed

+34
-13
lines changed

2 files changed

+34
-13
lines changed

src/lib/common/MultiSelect.svelte

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,9 @@
8282
function changeSearchValue(e) {
8383
searchValue = e.target.value || '';
8484
if (searchValue) {
85-
innerOptions = refOptions.filter(x => x.value.includes(searchValue));
85+
innerOptions = [...refOptions.filter(x => x.value.includes(searchValue))];
8686
} else {
87-
innerOptions = refOptions;
87+
innerOptions = [...refOptions];
8888
}
8989
9090
verifySelectAll();
@@ -96,20 +96,27 @@
9696
* @param {any} option
9797
*/
9898
function checkOption(e, option) {
99-
const found = innerOptions.find(x => x.key == option.key);
100-
const refFound = refOptions.find(x => x.key == option.key);
99+
innerOptions = innerOptions.map(x => {
100+
if (x.key == option.key) {
101+
x.checked = e == null ? !x.checked : e.target.checked;
102+
}
103+
return { ...x };
104+
});
101105
102-
if (found && refFound) {
103-
found.checked = e.target.checked;
104-
refFound.checked = e.target.checked;
105-
changeDisplayText();
106-
sendEvent();
107-
}
106+
refOptions = refOptions.map(x => {
107+
if (x.key == option.key) {
108+
x.checked = e == null ? !x.checked : e.target.checked;
109+
}
110+
return { ...x };
111+
});
112+
113+
changeDisplayText();
114+
sendEvent();
108115
}
109116
110117
/** @param {any} e */
111118
function checkSelectAll(e) {
112-
selectAllChecked = e.target.checked;
119+
selectAllChecked = e == null ? !selectAllChecked : e.target.checked;
113120
innerOptions = innerOptions.map(x => {
114121
return { ...x, checked: selectAllChecked }
115122
});
@@ -275,7 +282,12 @@
275282
</div>
276283
{#if innerOptions.length > 0}
277284
{#if selectAll}
278-
<li class="option-item">
285+
<!-- svelte-ignore a11y-click-events-have-key-events -->
286+
<!-- svelte-ignore a11y-no-noninteractive-element-interactions -->
287+
<li
288+
class="option-item clickable"
289+
on:click={() => checkSelectAll(null)}
290+
>
279291
<div class="line-align-center select-box">
280292
<Input
281293
type="checkbox"
@@ -289,7 +301,12 @@
289301
</li>
290302
{/if}
291303
{#each innerOptions as option, idx (idx)}
292-
<li class="option-item">
304+
<!-- svelte-ignore a11y-click-events-have-key-events -->
305+
<!-- svelte-ignore a11y-no-noninteractive-element-interactions -->
306+
<li
307+
class="option-item clickable"
308+
on:click={() => checkOption(null, option)}
309+
>
293310
<div class="line-align-center select-box">
294311
<Input
295312
type="checkbox"

src/lib/scss/custom/components/_multiselect.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@
6969
gap: 3px;
7070
padding: 5px 10px;
7171

72+
&:hover {
73+
background-color: aliceblue;
74+
}
75+
7276
.select-box {
7377
flex: 0 0 10%;
7478
max-width: 20px;

0 commit comments

Comments
 (0)