feat(SelectMenu): handle function in showCreateOptionWhen prop (#1853)

Co-authored-by: Benjamin Canac <canacb1@gmail.com>
This commit is contained in:
Vincent Ratier
2024-07-18 12:51:01 +01:00
committed by GitHub
parent 6aaf12b9af
commit 7e974b55d7
3 changed files with 78 additions and 2 deletions

View File

@@ -265,7 +265,7 @@ export default defineComponent({
default: false
},
showCreateOptionWhen: {
type: String as PropType<'always' | 'empty'>,
type: [String, Function] as PropType<'always' | 'empty' | ((query: string, results: any[]) => boolean)>,
default: () => configMenu.default.showCreateOptionWhen
},
placeholder: {
@@ -494,7 +494,11 @@ export default defineComponent({
return null
}
}
if (typeof props.showCreateOptionWhen === 'function') {
if (!props.showCreateOptionWhen(query.value, filteredOptions.value)) {
return null
}
}
return ['string', 'number'].includes(typeof props.modelValue) ? query.value : { [props.optionAttribute]: query.value }
})