Skip to content

Commit 6961bbb

Browse files
fix(QRadio/QCheckbox/QToggle): doesn't work normally when value is not proxy object (#13467)
* fix(QRadio): doesn't work normally when value is not proxy object Fixes #13457 * fix(QCheckbox): doesn't work normally when value is not proxy object * perf(use-checkbox): compute toRaw(props.val) only once in "index" Co-authored-by: Razvan Stoenescu <razvan.stoenescu@gmail.com>
1 parent b3f991d commit 6961bbb

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

ui/src/components/checkbox/use-checkbox.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { h, ref, computed, getCurrentInstance } from 'vue'
1+
import { h, ref, computed, getCurrentInstance, toRaw } from 'vue'
22

33
import useDark, { useDarkProps } from '../../composables/private/use-dark.js'
44
import useSize, { useSizeProps } from '../../composables/private/use-size.js'
@@ -61,22 +61,23 @@ export default function (type, getInner) {
6161
props.val !== void 0 && Array.isArray(props.modelValue)
6262
)
6363

64-
const index = computed(() => (
65-
modelIsArray.value === true
66-
? props.modelValue.indexOf(props.val)
64+
const index = computed(() => {
65+
const val = toRaw(props.val)
66+
return modelIsArray.value === true
67+
? props.modelValue.findIndex(opt => toRaw(opt) === val)
6768
: -1
68-
))
69+
})
6970

7071
const isTrue = computed(() => (
7172
modelIsArray.value === true
7273
? index.value > -1
73-
: props.modelValue === props.trueValue
74+
: toRaw(props.modelValue) === toRaw(props.trueValue)
7475
))
7576

7677
const isFalse = computed(() => (
7778
modelIsArray.value === true
7879
? index.value === -1
79-
: props.modelValue === props.falseValue
80+
: toRaw(props.modelValue) === toRaw(props.falseValue)
8081
))
8182

8283
const isIndeterminate = computed(() =>

ui/src/components/radio/QRadio.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { h, ref, computed, getCurrentInstance } from 'vue'
1+
import { h, ref, computed, getCurrentInstance, toRaw } from 'vue'
22

33
import QIcon from '../icon/QIcon.js'
44

@@ -64,7 +64,7 @@ export default createComponent({
6464
const rootRef = ref(null)
6565
const { refocusTargetEl, refocusTarget } = useRefocusTarget(props, rootRef)
6666

67-
const isTrue = computed(() => props.modelValue === props.val)
67+
const isTrue = computed(() => toRaw(props.modelValue) === toRaw(props.val))
6868

6969
const classes = computed(() =>
7070
'q-radio cursor-pointer no-outline row inline no-wrap items-center'

0 commit comments

Comments
 (0)