Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(SelectMenu): handle Boolean type as model value #1550

Merged
merged 3 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/content/2.components/select-menu.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ componentProps:
---
::

If you only want to select a single object property rather than the whole object as value, you can set the `value-attribute` property. This prop defaults to `null`.
If you only want to select a single object property rather than the whole object as value, you can set the `value-attribute` property. This prop defaults to `null`.The value of the `value-attribute` field in options must be unique.

::component-example
---
Expand Down
6 changes: 3 additions & 3 deletions src/runtime/components/forms/SelectMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ export default defineComponent({
inheritAttrs: false,
props: {
modelValue: {
type: [String, Number, Object, Array],
type: [String, Number, Object, Array, Boolean],
default: ''
},
query: {
Expand Down Expand Up @@ -362,7 +362,7 @@ export default defineComponent({
} else {
return null
}
} else if (props.modelValue) {
} else if (props.modelValue !== undefined && props.modelValue !== null) {
if (props.valueAttribute) {
const option = props.options.find(option => option[props.valueAttribute] === props.modelValue)
return option ? option[props.optionAttribute] : null
Expand All @@ -387,7 +387,7 @@ export default defineComponent({
variant?.replaceAll('{color}', color.value),
(isLeading.value || slots.leading) && ui.value.leading.padding[size.value],
(isTrailing.value || slots.trailing) && ui.value.trailing.padding[size.value]
), props.placeholder && !props.modelValue && ui.value.placeholder, props.selectClass)
), props.placeholder && (props.modelValue === undefined && props.modelValue === null) && ui.value.placeholder, props.selectClass)
})

const isLeading = computed(() => {
Expand Down
Loading