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

feat(ui): add input event to QInput #17543

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions ui/playground/src/pages/form/input.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
</div>
<q-input class="gigi" v-bind="props" outlined :model-value="text" @change="val => { text = val }" label="Label" label-color="green" />

<div class="text-h6">
Always (@input)
</div>
<q-input class="gigi" v-bind="props" outlined :model-value="text" @input="val => { text = val }" label="Label" label-color="green" />

<div class="text-h6">
Standard
</div>
Expand Down
2 changes: 1 addition & 1 deletion ui/playground/src/pages/form/select-part-7-text.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
fill-input
hide-selected
@filter="filterOptions"
@update:model-value-value="val => { model = val }"
@update:model-value="val => { model = val }"
>
<template v-slot:no-option>
<q-item>
Expand Down
19 changes: 11 additions & 8 deletions ui/src/components/input/QInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export default createComponent({

emits: [
...useFieldEmits,
'paste', 'change',
'paste', 'change', 'input',
'keydown', 'click', 'animationend'
],

Expand Down Expand Up @@ -71,7 +71,7 @@ export default createComponent({

const onComposition = useKeyComposition(onInput)

const state = useFieldState({ changeEvent: true })
const state = useFieldState({ changeEvent: true, inputEvent: true })

const isTextarea = computed(() =>
props.type === 'textarea' || props.autogrow === true
Expand Down Expand Up @@ -225,21 +225,22 @@ export default createComponent({

if (props.type === 'file') {
emit('update:modelValue', e.target.files)
emit('input', e.target.files)
return
}

const val = e.target.value

if (e.target.qComposing === true) {
temp.value = val

return
}

if (hasMask.value === true) {
updateMaskValue(val, false, e.inputType)
}
else {
if (e.target.qComposing === true) {
temp.value = val
emit('input', val)

return
}
emitValue(val)

if (isTypeText.value === true && e.target === document.activeElement) {
Expand All @@ -266,6 +267,8 @@ export default createComponent({
}

function emitValue (val, stopWatcher) {
emit('input', val)

emitValueFn = () => {
emitTimer = null

Expand Down
10 changes: 10 additions & 0 deletions ui/src/components/input/QInput.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,16 @@
}
}
},
"input": {
"desc": "Emitted when inputs new value; Also emitted during IME composition process; No debounce",
"params": {
"value": {
"type": [ "String", "null" ],
"desc": "New input value",
"required": true
}
}
},

"click": { "internal": true },
"paste": { "internal": true },
Expand Down
4 changes: 3 additions & 1 deletion ui/src/composables/private.use-field/use-field.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export const useFieldProps = {

export const useFieldEmits = [ 'update:modelValue', 'clear', 'focus', 'blur' ]

export function useFieldState ({ requiredForAttr = true, tagProp, changeEvent = false } = {}) {
export function useFieldState ({ requiredForAttr = true, tagProp, changeEvent = false, inputEvent = false } = {}) {
const { props, proxy } = getCurrentInstance()

const isDark = useDark(props, proxy.$q)
Expand All @@ -83,6 +83,7 @@ export function useFieldState ({ requiredForAttr = true, tagProp, changeEvent =
return {
requiredForAttr,
changeEvent,
inputEvent,
tag: tagProp === true
? computed(() => props.tag)
: { value: 'label' },
Expand Down Expand Up @@ -345,6 +346,7 @@ export default function (state) {

emit('update:modelValue', null)
state.changeEvent === true && emit('change', null)
state.inputEvent === true && emit('input', null)
emit('clear', props.modelValue)

nextTick(() => {
Expand Down
Loading