diff --git a/packages/ui/src/components/base/DropdownSelect.vue b/packages/ui/src/components/base/DropdownSelect.vue index 91b33bf0..0642c4b5 100644 --- a/packages/ui/src/components/base/DropdownSelect.vue +++ b/packages/ui/src/components/base/DropdownSelect.vue @@ -58,7 +58,7 @@ :value="option" :name="name" /> - + @@ -101,10 +101,14 @@ const props = defineProps({ }, displayName: { type: Function, - default: (option) => option, + default: undefined, }, }) +function getOptionLabel(option) { + return props.displayName?.(option) ?? option +} + const emit = defineEmits(['input', 'change', 'update:modelValue']) const dropdownVisible = ref(false) @@ -114,7 +118,7 @@ const dropdown = ref(null) const optionElements = ref(null) const selectedOption = computed(() => { - return props.displayName(selectedValue.value) || props.placeholder || 'Select an option' + return getOptionLabel(selectedValue.value) ?? props.placeholder ?? 'Select an option' }) const radioValue = computed({ diff --git a/packages/ui/src/components/base/ManySelect.vue b/packages/ui/src/components/base/ManySelect.vue index 9ae18c36..1e340b91 100644 --- a/packages/ui/src/components/base/ManySelect.vue +++ b/packages/ui/src/components/base/ManySelect.vue @@ -43,7 +43,7 @@ class="!w-full" :color="manyValues.includes(option) ? 'secondary' : 'default'" > - {{ displayName?.(option) }} + {{ getOptionLabel(option) }} - {{ displayName?.(option) }} + {{ getOptionLabel(option) }} option as string, + displayName: undefined, search: false, dropdownId: '', dropdownClass: '', @@ -106,6 +106,10 @@ const props = withDefaults( }, ) +function getOptionLabel(option: Option): string { + return props.displayName?.(option) ?? (option as string) +} + const emit = defineEmits(['update:modelValue', 'change']) const selectedValues = ref(props.modelValue || []) const searchInput = ref() @@ -127,7 +131,7 @@ const filteredOptions = computed(() => { return props.options.filter( (x) => !searchQuery.value || - props.displayName(x).toLowerCase().includes(searchQuery.value.toLowerCase()), + getOptionLabel(x).toLowerCase().includes(searchQuery.value.toLowerCase()), ) }) diff --git a/packages/ui/src/components/search/SearchDropdown.vue b/packages/ui/src/components/search/SearchDropdown.vue index 13d25d14..340020c3 100644 --- a/packages/ui/src/components/search/SearchDropdown.vue +++ b/packages/ui/src/components/search/SearchDropdown.vue @@ -51,10 +51,10 @@
- {{ displayName(option.title) }} + {{ getOptionLabel(option.title) }}
- {{ displayName(option.subtitle) }} + {{ getOptionLabel(option.subtitle) }}
@@ -98,7 +98,7 @@ const props = defineProps({ }, displayName: { type: Function, - default: (option) => option, + default: undefined, }, circledIcons: { type: Boolean, @@ -106,6 +106,10 @@ const props = defineProps({ }, }) +function getOptionLabel(option) { + return props.displayName?.(option) ?? option +} + const emit = defineEmits(['input', 'onSelected', 'update:modelValue', 'enter']) const dropdownVisible = ref(false)