Skip to content
This repository was archived by the owner on Mar 18, 2025. It is now read-only.

Commit 9a2dfe7

Browse files
committed
wip
1 parent a43ec9b commit 9a2dfe7

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

resources/js/components/custom-select.js

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ export default function customSelect(state) {
1717
options: [],
1818
currentIndex: -1,
1919
query: '',
20+
previousDisplay: '',
21+
canMakeSelection: true,
2022

2123
get activeDescendant() {
2224
return this.currentIndex > -1
@@ -56,10 +58,6 @@ export default function customSelect(state) {
5658

5759
$watch('value', value => {
5860
this.updateDisplay(value);
59-
60-
if (this.filterable) {
61-
this.refreshOptionsIfNeeded();
62-
}
6361
});
6462
$watch('query', value => this.filter(value));
6563
$watch('wireFilter', () => {
@@ -143,6 +141,14 @@ export default function customSelect(state) {
143141
},
144142

145143
choose(value) {
144+
if (! this.canMakeSelection) {
145+
return;
146+
}
147+
148+
// Attempt to prevent options from being selected and de-selected in the same click sometimes...
149+
this.canMakeSelection = false;
150+
setTimeout(() => this.canMakeSelection = true, 250);
151+
146152
if (this.multiple) {
147153
return this.chooseForMultiple(value);
148154
}
@@ -201,16 +207,19 @@ export default function customSelect(state) {
201207
updateDisplayForMultiple(value) {
202208
const length = value.length;
203209
if (length === 0) {
210+
this.previousDisplay = '';
211+
204212
return this.display = this.placeholderMarkup;
205213
}
206214

207215
const $li = this.optionChildren()[this.optionIndex(value[0])];
208216

209-
if (! $li) {
217+
if (! $li && ! this.previousDisplay) {
210218
return this.display = `${length} Selected`;
211219
}
212220

213-
let display = $li.children[0].innerHTML;
221+
let display = $li ? $li.children[0].innerHTML : this.previousDisplay;
222+
this.previousDisplay = display;
214223
if ((length - 1) > 0) {
215224
display += `<span class="text-xs text-cool-gray-500">+ ${length - 1}</span>`;
216225
}

0 commit comments

Comments
 (0)