Skip to content
This repository was archived by the owner on Mar 27, 2025. It is now read-only.

Commit 0b3fcc5

Browse files
committed
fix(useFormInput): event issues not working as intended fixes bootstrap-vue-next#1089
1 parent 6b145a6 commit 0b3fcc5

File tree

1 file changed

+15
-22
lines changed

1 file changed

+15
-22
lines changed

packages/bootstrap-vue-next/src/composables/useFormInput.ts

+15-22
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,19 @@ export default (
9090
lazyBoolean.value === true ? NaN : debounceMaxWaitNumber.value
9191
)
9292

93-
const updateModelValue = useDebounceFn(
93+
const internalUpdateModelValue = useDebounceFn(
9494
(value: string | number | undefined) => {
9595
modelValue.value = value
9696
},
9797
computedDebounceValueWithLazy,
9898
{maxWait: computedDebounceMaxWaitValueWithLazy}
9999
)
100100

101+
const updateModelValue = (value: string | number | undefined, force = false) => {
102+
if (lazyBoolean.value === true && force === false) return
103+
internalUpdateModelValue(value)
104+
}
105+
101106
const {focused} = useFocus(input, {
102107
initialValue: autofocusBoolean.value,
103108
})
@@ -118,12 +123,6 @@ export default (
118123
return value
119124
}
120125

121-
const handleAutofocus = () => {
122-
if (autofocusBoolean.value) {
123-
focused.value = true
124-
}
125-
}
126-
127126
onMounted(() => {
128127
if (input.value) {
129128
input.value.value = modelValue.value as string
@@ -132,7 +131,9 @@ export default (
132131

133132
onActivated(() => {
134133
nextTick(() => {
135-
handleAutofocus()
134+
if (autofocusBoolean.value) {
135+
focused.value = true
136+
}
136137
})
137138
})
138139

@@ -148,14 +149,10 @@ export default (
148149
return
149150
}
150151

151-
if (lazyBoolean.value) return
152-
153152
const nextModel = _getModelValue(formattedValue)
154153

155-
if (modelValue.value !== nextModel) {
156-
inputValue = value
157-
updateModelValue(nextModel)
158-
}
154+
inputValue = value
155+
updateModelValue(nextModel)
159156

160157
emit('input', formattedValue)
161158
}
@@ -168,14 +165,10 @@ export default (
168165
return
169166
}
170167

171-
if (!lazyBoolean.value) return
172168
inputValue = value
173-
updateModelValue(formattedValue)
169+
updateModelValue(formattedValue, true)
174170

175-
const nextModel = _getModelValue(formattedValue)
176-
if (modelValue.value !== nextModel) {
177-
emit('change', formattedValue)
178-
}
171+
emit('change', formattedValue)
179172
}
180173

181174
const onBlur = (evt: FocusEvent) => {
@@ -186,7 +179,7 @@ export default (
186179
const formattedValue = _formatValue(value, evt, true)
187180

188181
inputValue = value
189-
updateModelValue(formattedValue)
182+
updateModelValue(formattedValue, true)
190183
}
191184

192185
const focus = () => {
@@ -197,7 +190,7 @@ export default (
197190

198191
const blur = () => {
199192
if (!disabledBoolean.value) {
200-
input.value?.blur()
193+
focused.value = false
201194
}
202195
}
203196

0 commit comments

Comments
 (0)