Skip to content

Commit

Permalink
fix(autocomplete): [autocomplete] fix form validate error when select…
Browse files Browse the repository at this point in the history
… suggestion option (#2296)
  • Loading branch information
gimmyhehe authored Oct 21, 2024
1 parent b19efbc commit 80bcc5d
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 20 deletions.
2 changes: 1 addition & 1 deletion packages/renderless/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@opentiny/vue-renderless",
"version": "3.18.4",
"version": "3.18.5",
"private": true,
"description": "An enterprise-class UI component library, support both Vue.js 2 and Vue.js 3, as well as PC and mobile.",
"author": "OpenTiny Team",
Expand Down
13 changes: 9 additions & 4 deletions packages/renderless/src/autocomplete/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ export const handleFocus =

export const handleBlur =
({ emit, state, dispatch, props }: Pick<IAutoCompleteRenderlessParams, 'emit' | 'state' | 'dispatch' | 'props'>) =>
(event) => {
() => {
state.suggestionDisabled = true
emit('blur', event)
emit('blur')
if (state.validateEvent) {
dispatch(FORM_ITEM, FORM_EVENT.blur, [props.modelValue])
}
Expand Down Expand Up @@ -165,17 +165,22 @@ export const select =
emit,
nextTick,
props,
state
state,
dispatch
}: {
emit: IAutoCompleteRenderlessParamUtils['emit']
nextTick: IAutoCompleteRenderlessParamUtils['nextTick']
props: IAutoCompleteProps
state: IAutoCompleteState
}) =>
(item) => {
emit('update:modelValue', item[props.valueKey])
const value = item[props.valueKey]
emit('update:modelValue', value)
emit('select', item)

if (state.validateEvent) {
dispatch(FORM_ITEM, FORM_EVENT.change, [value])
}
nextTick(() => {
state.activated = false
state.suggestions = []
Expand Down
3 changes: 1 addition & 2 deletions packages/renderless/src/autocomplete/vue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ import type {

export const api = [
'state',
'select',
'suggestionState',
'getInput',
'handleChange',
Expand Down Expand Up @@ -125,7 +124,7 @@ const initApi = ({
mounted: mounted({ vm, state, suggestionState }),
highlight: highlight({ constants, vm, state }),
handleClear: handleClear({ emit, state }),
select: select({ emit, nextTick, props, state }),
select: select({ emit, nextTick, props, state, dispatch }),
watchVisible: watchVisible({ suggestionState, vm }),
handleChange: handleChange({ api, emit, state, props, dispatch }),
handleFocus: handleFocus({ api, emit, props, state }),
Expand Down
24 changes: 12 additions & 12 deletions packages/vue/src/autocomplete/package.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
{
"name": "@opentiny/vue-autocomplete",
"version": "3.18.0",
"type": "module",
"version": "3.18.1",
"description": "",
"license": "MIT",
"sideEffects": false,
"main": "lib/index.js",
"module": "index.ts",
"sideEffects": false,
"type": "module",
"devDependencies": {
"@opentiny-internal/vue-test-utils": "workspace:*",
"vitest": "^0.31.0"
},
"scripts": {
"build": "pnpm -w build:ui $npm_package_name",
"//postversion": "pnpm build"
},
"dependencies": {
"@opentiny/vue-renderless": "workspace:~",
"@opentiny/vue-common": "workspace:~",
"@opentiny/vue-icon": "workspace:~",
"@opentiny/vue-input": "workspace:~",
"@opentiny/vue-renderless": "workspace:~",
"@opentiny/vue-scrollbar": "workspace:~",
"@opentiny/vue-icon": "workspace:~",
"@opentiny/vue-common": "workspace:~",
"@opentiny/vue-theme": "workspace:~"
},
"license": "MIT"
}
"devDependencies": {
"@opentiny-internal/vue-test-utils": "workspace:*",
"vitest": "^0.31.0"
}
}
2 changes: 1 addition & 1 deletion packages/vue/src/autocomplete/src/pc.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
ref="input"
v-bind="f($props, $attrs)"
front-clear-icon
v-clickoutside="handleBlur"
@update:modelValue="handleChange"
:validate-event="false"
@focus="handleFocus"
@blur="handleBlur"
@clear="handleClear"
@keydown.up.prevent="highlight(state.highlightedIndex - 1)"
@keydown.down.prevent="highlight(state.highlightedIndex + 1)"
Expand Down

0 comments on commit 80bcc5d

Please sign in to comment.