Skip to content

Commit

Permalink
fix(pro:search): item created by shortcut shoule be set active (#1554)
Browse files Browse the repository at this point in the history
item created by shortcut shoule be set active after created and onItemCreate should be called
  • Loading branch information
sallerli1 committed May 18, 2023
1 parent cbaea04 commit 31e433c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 6 deletions.
Expand Up @@ -9,7 +9,7 @@ import type { SearchState } from '../../composables/useSearchStates'

import { computed, defineComponent, inject, normalizeClass, ref, watch } from 'vue'

import { useState } from '@idux/cdk/utils'
import { callEmit, useState } from '@idux/cdk/utils'
import { type IconInstance, IxIcon } from '@idux/components/icon'
import { IxInput } from '@idux/components/input'

Expand All @@ -20,7 +20,9 @@ export default defineComponent({
props: quickSelectPanelItemProps,
setup(props, { slots }) {
const {
props: proSearchProps,
mergedPrefixCls,
convertStateToValue,
createSearchState,
getSearchStatesByFieldKey,
updateSegmentValue,
Expand Down Expand Up @@ -67,6 +69,10 @@ export default defineComponent({
searchStateKey = createSearchState(props.searchField.key, {
value,
})!.key
callEmit(proSearchProps.onItemCreate, {
...convertStateToValue(searchStateKey),
nameInput: props.searchField.label,
})
} else if (searchDataSegment.value?.name) {
updateSegmentValue(value, searchDataSegment.value.name, searchState.value.key)
}
Expand Down
Expand Up @@ -7,6 +7,7 @@

import { defineComponent, inject } from 'vue'

import { callEmit } from '@idux/cdk/utils'
import { IxIcon } from '@idux/components/icon'

import { proSearchContext } from '../../token'
Expand All @@ -15,14 +16,34 @@ import { quickSelectPanelShortcutProps } from '../../types'
export default defineComponent({
props: quickSelectPanelShortcutProps,
setup(props) {
const { mergedPrefixCls, createSearchState, updateSearchState, getSearchStatesByFieldKey } =
inject(proSearchContext)!
const {
props: proSearchProps,
mergedPrefixCls,
convertStateToValue,
createSearchState,
updateSearchState,
getSearchStatesByFieldKey,
setActiveSegment,
} = inject(proSearchContext)!

const handleClick = () => {
const fieldKey = props.searchField.key
if (!!props.searchField.multiple || !getSearchStatesByFieldKey(fieldKey).length) {
const state = createSearchState(props.searchField.key)
state && updateSearchState(state.key)
if (!props.searchField.multiple && getSearchStatesByFieldKey(fieldKey).length) {
return
}

const state = createSearchState(props.searchField.key)

if (state) {
updateSearchState(state.key)
callEmit(proSearchProps.onItemCreate, {
...convertStateToValue(state.key),
nameInput: props.searchField.label,
})
setActiveSegment({
itemKey: state.key,
name: state.segmentValues[0]?.name,
})
}
}

Expand Down

0 comments on commit 31e433c

Please sign in to comment.