Skip to content

Commit

Permalink
fix(forms)!: normalize input emits (#1560)
Browse files Browse the repository at this point in the history
  • Loading branch information
romhml committed Mar 25, 2024
1 parent 7d6b5c3 commit 92e7362
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/runtime/components/forms/Checkbox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export default defineComponent({
})
const onChange = (event: Event) => {
emit('change', event)
emit('change', (event.target as HTMLInputElement).value)
emitFormChange()
}
Expand Down
3 changes: 2 additions & 1 deletion src/runtime/components/forms/Input.vue
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ export default defineComponent({
default: () => ({})
}
},
emits: ['update:modelValue', 'blur'],
emits: ['update:modelValue', 'blur', 'change'],
setup (props, { emit, slots }) {
const { ui, attrs } = useUI('input', toRef(props, 'ui'), config, toRef(props, 'class'))
Expand Down Expand Up @@ -206,6 +206,7 @@ export default defineComponent({
const onChange = (event: Event) => {
const value = (event.target as HTMLInputElement).value
emit('change', value)
if (modelModifiers.value.lazy) {
updateInput(value)
Expand Down
13 changes: 7 additions & 6 deletions src/runtime/components/forms/InputMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
autocomplete="off"
v-bind="attrs"
:display-value="() => query ? query : label"
@change="onChange"
@change="onQueryChange"
/>

<span v-if="(isLeading && leadingIconName) || $slots.leading" :class="leadingWrapperIconClass">
Expand Down Expand Up @@ -418,14 +418,15 @@ export default defineComponent({
}
})
function onUpdate (event: any) {
function onUpdate (value: any) {
query.value = ''
emit('update:modelValue', event)
emit('change', event)
emit('update:modelValue', value)
emit('change', value)
emitFormChange()
}
function onChange (event: any) {
function onQueryChange (event: any) {
query.value = event.target.value
}
Expand Down Expand Up @@ -459,7 +460,7 @@ export default defineComponent({
// eslint-disable-next-line vue/no-dupe-keys
query,
onUpdate,
onChange
onQueryChange
}
}
})
Expand Down
10 changes: 7 additions & 3 deletions src/runtime/components/forms/Radio.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
type="radio"
:class="inputClass"
v-bind="attrs"
@change="onChange"
>
</div>
<div v-if="label || $slots.label" :class="ui.inner">
Expand Down Expand Up @@ -111,14 +112,16 @@ export default defineComponent({
},
set (value) {
emit('update:modelValue', value)
emit('change', value)
if (!radioGroup) {
emitFormChange()
}
}
})
function onChange (event: Event) {
emit('change', (event.target as HTMLInputElement).value)
}
const inputClass = computed(() => {
return twMerge(twJoin(
ui.value.base,
Expand All @@ -139,7 +142,8 @@ export default defineComponent({
// eslint-disable-next-line vue/no-dupe-keys
name,
// eslint-disable-next-line vue/no-dupe-keys
inputClass
inputClass,
onChange
}
}
})
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/components/forms/Range.vue
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export default defineComponent({
})
const onChange = (event: Event) => {
emit('change', event)
emit('change', (event.target as HTMLInputElement).value)
emitFormChange()
}
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/components/forms/Select.vue
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,8 @@ export default defineComponent({
}
const onChange = (event: Event) => {
emit('change', (event.target as HTMLInputElement).value)
emitFormChange()
emit('change', event)
}
const guessOptionValue = (option: any) => {
Expand Down
5 changes: 3 additions & 2 deletions src/runtime/components/forms/SelectMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -507,11 +507,12 @@ export default defineComponent({
function onUpdate (event: any) {
emit('update:modelValue', event)
emit('change', event)
emitFormChange()
}
function onChange (event: any) {
emit('change', (event.target as HTMLInputElement).value)
emitFormChange()
query.value = event.target.value
}
Expand Down
3 changes: 2 additions & 1 deletion src/runtime/components/forms/Textarea.vue
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export default defineComponent({
default: () => ({})
}
},
emits: ['update:modelValue', 'blur'],
emits: ['update:modelValue', 'blur', 'change'],
setup (props, { emit }) {
const { ui, attrs } = useUI('textarea', toRef(props, 'ui'), config, toRef(props, 'class'))
Expand Down Expand Up @@ -192,6 +192,7 @@ export default defineComponent({
const onChange = (event: Event) => {
const value = (event.target as HTMLInputElement).value
emit('change', value)
if (modelModifiers.value.lazy) {
updateInput(value)
Expand Down
2 changes: 2 additions & 0 deletions src/runtime/components/forms/Toggle.vue
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ export default defineComponent({
},
set (value) {
emit('update:modelValue', value)
emit('change', value)
emitFormChange()
}
})
Expand Down

0 comments on commit 92e7362

Please sign in to comment.