8000 fix(CFormCheck): emits value instead of checked state on model value … · coreui/coreui-vue@a85d8bd · GitHub
[go: up one dir, main page]

Skip to content

Commit a85d8bd

Browse files
committed
fix(CFormCheck): emits value instead of checked state on model value change
1 parent ec013e7 commit a85d8bd

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

packages/coreui-vue/src/components/form/CFormCheck.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import { defineComponent, h } from 'vue'
1+
import { computed, defineComponent, h } from 'vue'
22

33
import { CButton } from '../button'
44
import { CFormControlValidation } from './CFormControlValidation'
55
import { CFormLabel } from './CFormLabel'
6+
import { any } from 'vue-types'
67

78
const CFormCheck = defineComponent({
89
name: 'CFormCheck',
@@ -94,6 +95,10 @@ const CFormCheck = defineComponent({
9495
* Set component validation state to valid.
9596
*/
9697
valid: Boolean,
98+
/**
99+
* The value attribute of component.
100+
*/
101+
value: String,
97102
},
98103
emits: [
99104
/**
@@ -107,9 +112,9 @@ const CFormCheck = defineComponent({
107112
],
108113
setup(props, { attrs, emit, slots }) {
109114
const handleChange = (event: InputEvent) => {
110-
const target = event.target as HTMLInputElement
115+
console.log(event)
111116
emit('change', event)
112-
emit('update:modelValue', target.checked)
117+
emit('update:modelValue', (event.target as HTMLInputElement).value)
113118
}
114119

115120
const className = [
@@ -132,15 +137,18 @@ const CFormCheck = defineComponent({
132137
},
133138
]
134139

140+
const isChecked = computed(() => props.modelValue == props.value)
141+
135142
const formControl = () => {
136143
return h('input', {
137144
...attrs,
138-
...(props.modelValue && { checked: props.modelValue }),
145+
...(props.modelValue && { checked: isChecked.value }),
139146
class: inputClassName,
140147
id: props.id,
141148
indeterminate: props.indeterminate,
142149
onChange: (event: InputEvent) => handleChange(event),
143150
type: props.type,
151+
value: props.value,
144152
})
145153
}
146154

0 commit comments

Comments
 (0)
0