Skip to content

Commit 693a9b0

Browse files
committed
fixes for vf-smart-select when the value or title is 0
1 parent b5d5721 commit 693a9b0

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@signal24/vue-foundation",
33
"type": "module",
4-
"version": "4.25.2",
4+
"version": "4.25.3",
55
"description": "Common components, directives, and helpers for Vue 3 apps",
66
"module": "./dist/vue-foundation.es.js",
77
"exports": {

src/components/vf-smart-select.vue

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ watch(shouldDisplayOptions, () => {
274274
setTimeout(handleOptionsDisplayed, 0);
275275
} else {
276276
isSearching.value = false;
277-
searchText.value = selectedOptionTitle.value || '';
277+
searchText.value = selectedOptionTitle.value ?? '';
278278
279279
if (optionsContainer.value) {
280280
optionsContainer.value.style.visibility = 'hidden';
@@ -283,11 +283,14 @@ watch(shouldDisplayOptions, () => {
283283
});
284284
285285
watch(effectiveOptions, () => {
286-
if (props.modelValue && !selectedOption.value) {
286+
if (props.modelValue !== null && selectedOption.value === null) {
287287
handleValueChanged();
288288
}
289289
290-
if ((highlightedOptionKey.value || isSearching.value) && !effectiveOptions.value.find(option => option.key == highlightedOptionKey.value)) {
290+
if (
291+
(highlightedOptionKey.value !== null || isSearching.value) &&
292+
!effectiveOptions.value.find(option => option.key == highlightedOptionKey.value)
293+
) {
291294
highlightedOptionKey.value = effectiveOptions.value[0]?.key ?? NullSymbol;
292295
}
293296
});
@@ -308,7 +311,9 @@ onMounted(async () => {
308311
if (selectedOption.value !== props.modelValue) {
309312
emit(
310313
'update:modelValue',
311-
selectedOption.value && effectiveValueExtractor.value ? effectiveValueExtractor.value(selectedOption.value) : selectedOption.value
314+
selectedOption.value !== null && effectiveValueExtractor.value !== null
315+
? effectiveValueExtractor.value(selectedOption.value)
316+
: selectedOption.value
312317
);
313318
}
314319
});
@@ -324,7 +329,7 @@ async function loadRemoteOptions() {
324329
}
325330
326331
async function reloadOptions() {
327-
const effectiveSearchText = props.remoteSearch && isSearching.value && searchText.value ? searchText.value : null;
332+
const effectiveSearchText = props.remoteSearch && isSearching.value && searchText.value.length ? searchText.value : null;
328333
isLoading.value = true;
329334
loadedOptions.value = (await props.loadOptions?.(effectiveSearchText)) ?? [];
330335
isLoading.value = false;
@@ -517,7 +522,7 @@ function incrementHighlightedOption(increment: number) {
517522
function selectOption(option: VfSmartSelectOptionDescriptor<T>) {
518523
isSearching.value = false;
519524
520-
if (option.key == NullSymbol) {
525+
if (option.key === NullSymbol) {
521526
searchText.value = '';
522527
selectedOption.value = null;
523528
selectedOptionTitle.value = null;
@@ -532,20 +537,20 @@ function selectOption(option: VfSmartSelectOptionDescriptor<T>) {
532537
const realOption = selectedDecoratedOption!.ref;
533538
selectedOption.value = realOption!;
534539
selectedOptionTitle.value = effectiveFormatter.value(realOption!);
535-
searchText.value = selectedOptionTitle.value || '';
540+
searchText.value = selectedOptionTitle.value ?? '';
536541
}
537542
538543
searchField.value?.blur();
539544
focusNextInput();
540545
}
541546
542547
function handleValueChanged() {
543-
if (props.modelValue) {
548+
if (props.modelValue !== null) {
544549
selectedOption.value = effectiveValueExtractor.value
545550
? allOptions.value.find(o => props.modelValue === effectiveValueExtractor.value!(o))
546551
: props.modelValue;
547-
selectedOptionTitle.value = selectedOption.value ? effectiveFormatter.value(selectedOption.value) : null;
548-
searchText.value = selectedOptionTitle.value || '';
552+
selectedOptionTitle.value = selectedOption.value !== null ? effectiveFormatter.value(selectedOption.value) : null;
553+
searchText.value = selectedOptionTitle.value ?? '';
549554
} else {
550555
selectedOption.value = null;
551556
selectedOptionTitle.value = null;

0 commit comments

Comments
 (0)