Skip to content

Commit 0ebff6c

Browse files
committed
refactor: update events
1 parent 1fbf1bf commit 0ebff6c

File tree

5 files changed

+16
-37
lines changed

5 files changed

+16
-37
lines changed

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

+3-18
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { defineComponent, h, onMounted, watch, ref } from 'vue'
1+
import { defineComponent, h } from 'vue'
22
import { shape } from 'vue-types'
33

44
import { Color, Shape } from '../props'
@@ -120,21 +120,6 @@ const CFormCheck = defineComponent({
120120
'update:modelValue',
121121
],
122122
setup(props, { attrs, emit, slots }) {
123-
const checked = ref(attrs.checked)
124-
125-
onMounted(() => {
126-
if (props.modelValue && typeof props.modelValue === 'boolean') {
127-
console.log(props.modelValue)
128-
}
129-
})
130-
131-
watch(
132-
() => props.modelValue,
133-
() => {
134-
if (typeof props.modelValue === 'boolean') checked.value = props.modelValue
135-
},
136-
)
137-
138123
const handleChange = (event: InputEvent) => {
139124
const target = event.target as HTMLInputElement
140125
emit('change', event)
@@ -143,8 +128,7 @@ const CFormCheck = defineComponent({
143128

144129
const formControl = () => {
145130
return h('input', {
146-
...attrs,
147-
checked: checked.value,
131+
checked: props.modelValue,
148132
class: [
149133
props.button ? 'btn-check' : 'form-check-input',
150134
{
@@ -156,6 +140,7 @@ const CFormCheck = defineComponent({
156140
indeterminate: props.indeterminate,
157141
onChange: (event: InputEvent) => handleChange(event),
158142
type: props.type,
143+
...attrs,
159144
})
160145
}
161146
const formLabel = () => {

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

+9-9
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,11 @@ const CFormInput = defineComponent({
8585
'update:modelValue',
8686
],
8787
setup(props, { emit, slots }) {
88-
const handleChange = (event: InputEvent) => {
89-
const target = event.target as HTMLInputElement
90-
emit('change', event)
91-
emit('update:modelValue', target.value)
92-
}
88+
// const handleChange = (event: InputEvent) => {
89+
// const target = event.target as HTMLInputElement
90+
// emit('change', event)
91+
// emit('update:modelValue', target.value)
92+
// }
9393
const handleInput = (event: InputEvent) => {
9494
const target = event.target as HTMLInputElement
9595
emit('input', event)
@@ -100,9 +100,6 @@ const CFormInput = defineComponent({
100100
h(
101101
'input',
102102
{
103-
type: props.type,
104-
disabled: props.disabled,
105-
readonly: props.readonly,
106103
class: [
107104
props.plainText ? 'form-control-plaintext' : 'form-control',
108105
{
@@ -112,8 +109,11 @@ const CFormInput = defineComponent({
112109
'is-valid': props.valid,
113110
},
114111
],
115-
onChange: (event: InputEvent) => handleChange(event),
112+
disabled: props.disabled,
113+
// onChange: (event: InputEvent) => handleChange(event),
116114
onInput: (event: InputEvent) => handleInput(event),
115+
readonly: props.readonly,
116+
type: props.type,
117117
value: props.modelValue,
118118
},
119119
slots.default && slots.default(),

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ const CFormRange = defineComponent({
9090
steps: props.steps,
9191
readonly: props.readonly,
9292
type: 'range',
93-
value: props.modelValue || props.value,
93+
value: props.modelValue,
9494
},
9595
slots.default && slots.default(),
9696
)

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

-6
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,6 @@ const CFormTextarea = defineComponent({
6262
'update:modelValue',
6363
],
6464
setup(props, { emit, slots }) {
65-
const handleChange = (event: InputEvent) => {
66-
const target = event.target as HTMLInputElement
67-
emit('change', event)
68-
emit('update:modelValue', target.value)
69-
}
7065
const handleInput = (event: InputEvent) => {
7166
const target = event.target as HTMLInputElement
7267
emit('input', event)
@@ -86,7 +81,6 @@ const CFormTextarea = defineComponent({
8681
'is-valid': props.valid,
8782
},
8883
],
89-
onChange: (event: InputEvent) => handleChange(event),
9084
onInput: (event: InputEvent) => handleInput(event),
9185
value: props.modelValue,
9286
},
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`Customize (two) CFormInput component renders correctly 1`] = `"<input type=\\"color\\" disabled=\\"\\" readonly=\\"\\" class=\\"form-control form-control-color form-control-lg is-invalid is-valid\\">"`;
3+
exports[`Customize (two) CFormInput component renders correctly 1`] = `"<input class=\\"form-control form-control-color form-control-lg is-invalid is-valid\\" disabled=\\"\\" readonly=\\"\\" type=\\"color\\">"`;
44
5-
exports[`Customize CFormInput component renders correctly 1`] = `"<input type=\\"color\\" disabled=\\"\\" readonly=\\"\\" class=\\"form-control-plaintext form-control-color form-control-lg is-invalid is-valid\\">"`;
5+
exports[`Customize CFormInput component renders correctly 1`] = `"<input class=\\"form-control-plaintext form-control-color form-control-lg is-invalid is-valid\\" disabled=\\"\\" readonly=\\"\\" type=\\"color\\">"`;
66
7-
exports[`Loads and display CFormInput component renders correctly 1`] = `"<input type=\\"text\\" class=\\"form-control\\">"`;
7+
exports[`Loads and display CFormInput component renders correctly 1`] = `"<input class=\\"form-control\\" type=\\"text\\">"`;

0 commit comments

Comments
 (0)