Skip to content

Commit 44382cd

Browse files
authored
fix(SelectMenu/InputMenu): ensure object compare with by prop (#4791)
1 parent a72bb86 commit 44382cd

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/runtime/components/forms/InputMenu.vue

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,10 @@ export default defineComponent({
322322
}
323323
})
324324
325+
function isObject(object: any): object is boolean {
326+
return !Array.isArray(object) && object !== null && typeof object === 'object'
327+
}
328+
325329
const label = computed(() => {
326330
if (!props.modelValue) return null
327331
@@ -334,7 +338,7 @@ export default defineComponent({
334338
}
335339
336340
function compareValues(value1: any, value2: any) {
337-
if (by.value && typeof by.value !== 'function' && typeof value1 === 'object' && typeof value2 === 'object') {
341+
if (by.value && typeof by.value !== 'function' && isObject(value1) && isObject(value2)) {
338342
return isEqual(value1[props.by], value2[props.by])
339343
}
340344
return isEqual(value1, value2)

src/runtime/components/forms/SelectMenu.vue

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ export default defineComponent({
389389
390390
const selected = computed(() => {
391391
function compareValues(value1: any, value2: any) {
392-
if (by.value && typeof by.value !== 'function' && typeof value1 === 'object' && typeof value2 === 'object') {
392+
if (by.value && typeof by.value !== 'function' && isObject(value1) && isObject(value2)) {
393393
return isEqual(value1[by.value], value2[by.value])
394394
}
395395
return isEqual(value1, value2)
@@ -527,6 +527,10 @@ export default defineComponent({
527527
return get(obj, key)
528528
}
529529
530+
function isObject(object: any): object is boolean {
531+
return !Array.isArray(object) && object !== null && typeof object === 'object'
532+
}
533+
530534
const filteredOptions = computed(() => {
531535
if (!query.value || debouncedSearch) {
532536
return options.value

0 commit comments

Comments
 (0)