Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Input/SelectMenu): handle file type and change events #1570

Merged
merged 3 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions src/runtime/components/forms/Input.vue
Original file line number Diff line number Diff line change
Expand Up @@ -205,16 +205,19 @@ export default defineComponent({
}

const onChange = (event: Event) => {
const value = (event.target as HTMLInputElement).value
emit('change', value)

if (modelModifiers.value.lazy) {
updateInput(value)
}

// Update trimmed input so that it has same behavior as native input https://github.com/vuejs/core/blob/5ea8a8a4fab4e19a71e123e4d27d051f5e927172/packages/runtime-dom/src/directives/vModel.ts#L63
if (modelModifiers.value.trim) {
(event.target as HTMLInputElement).value = value.trim()
if (props.type === 'file') {
const value = (event.target as HTMLInputElement).files
emit('change', value)
} else {
const value = (event.target as HTMLInputElement).value
emit('change', value)
if (modelModifiers.value.lazy) {
updateInput(value)
}
// Update trimmed input so that it has same behavior as native input https://github.com/vuejs/core/blob/5ea8a8a4fab4e19a71e123e4d27d051f5e927172/packages/runtime-dom/src/directives/vModel.ts#L63
if (modelModifiers.value.trim) {
(event.target as HTMLInputElement).value = value.trim()
}
}
}

Expand Down
15 changes: 7 additions & 8 deletions src/runtime/components/forms/SelectMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
autofocus
autocomplete="off"
:class="uiMenu.input"
@change="onChange"
@change="onQueryChange"
/>
<component
:is="searchable ? 'HComboboxOption' : 'HListboxOption'"
Expand Down Expand Up @@ -505,14 +505,13 @@ export default defineComponent({
}
})

function onUpdate (event: any) {
emit('update:modelValue', event)
}

function onChange (event: any) {
emit('change', (event.target as HTMLInputElement).value)
function onUpdate (value: any) {
emit('update:modelValue', value)
emit('change', value)
emitFormChange()
}

function onQueryChange (event: any) {
query.value = event.target.value
}

Expand Down Expand Up @@ -547,7 +546,7 @@ export default defineComponent({
// eslint-disable-next-line vue/no-dupe-keys
query,
onUpdate,
onChange
onQueryChange
}
}
})
Expand Down
Loading