mirror of
https://github.com/ArthurDanjou/ui.git
synced 2026-01-19 14:31:47 +01:00
feat(SelectMenu): handle function in showCreateOptionWhen prop (#1853)
Co-authored-by: Benjamin Canac <canacb1@gmail.com>
This commit is contained in:
@@ -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 }
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user