Skip to content

Commit

Permalink
Merge b7d0242 into fdda882
Browse files Browse the repository at this point in the history
  • Loading branch information
sallerli1 committed Jul 25, 2023
2 parents fdda882 + b7d0242 commit ca4963c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
11 changes: 7 additions & 4 deletions packages/pro/search/src/ProSearch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,14 @@ export default defineComponent({
const tempSegmentInputRef = ref<HTMLInputElement>()

const searchValueContext = useSearchValues(props)
const { searchValues, searchValueEmpty } = searchValueContext
const { searchValues } = searchValueContext

Check warning on line 67 in packages/pro/search/src/ProSearch.tsx

View check run for this annotation

Codecov / codecov/patch

packages/pro/search/src/ProSearch.tsx#L67

Added line #L67 was not covered by tests
const resolvedSearchFieldsContext = useResolvedSearchFields(props, mergedPrefixCls, dateConfig)
const { fieldKeyMap } = resolvedSearchFieldsContext
const searchStateContext = useSearchStates(props, fieldKeyMap, searchValueContext)
const { initSearchStates, clearSearchState, updateSearchValues, isSegmentVisible } = searchStateContext
const { searchStates, initSearchStates, clearSearchState, updateSearchValues, isSegmentVisible } =
searchStateContext

const searchStateEmpty = computed(() => !searchStates.value || searchStates.value.length <= 0)

Check warning on line 74 in packages/pro/search/src/ProSearch.tsx

View check run for this annotation

Codecov / codecov/patch

packages/pro/search/src/ProSearch.tsx#L71-L74

Added lines #L71 - L74 were not covered by tests

const errors = useSearchItemErrors(props, searchValues)
const searchItems = useSearchItems(fieldKeyMap, searchStateContext.searchStates, errors)
Expand Down Expand Up @@ -196,11 +199,11 @@ export default defineComponent({
getKey={item => item.key ?? 'name-select'}
maxLabel={focused.value ? Number.MAX_SAFE_INTEGER : props.maxLabel}
/>
{searchValueEmpty.value && !isActive.value && (
{searchStateEmpty.value && !isActive.value && (

Check warning on line 202 in packages/pro/search/src/ProSearch.tsx

View check run for this annotation

Codecov / codecov/patch

packages/pro/search/src/ProSearch.tsx#L202

Added line #L202 was not covered by tests
<span class={`${prefixCls}-placeholder`}>{placeholder.value}</span>
)}
</div>
{!searchValueEmpty.value && clearable.value && !props.disabled && (
{!searchStateEmpty.value && clearable.value && !props.disabled && (

Check warning on line 206 in packages/pro/search/src/ProSearch.tsx

View check run for this annotation

Codecov / codecov/patch

packages/pro/search/src/ProSearch.tsx#L206

Added line #L206 was not covered by tests
<div
class={`${prefixCls}-clear-icon`}
onMousedown={handleClearBtnMouseDown}
Expand Down
6 changes: 1 addition & 5 deletions packages/pro/search/src/composables/useSearchValues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,22 @@
*/

import type { ProSearchProps, SearchValue } from '../types'

import { type ComputedRef, computed } from 'vue'
import type { ComputedRef } from 'vue'

import { useControlledProp } from '@idux/cdk/utils'

export interface SearchValueContext {
searchValues: ComputedRef<SearchValue[] | undefined>
searchValueEmpty: ComputedRef<boolean>
setSearchValues: (values: SearchValue[]) => void
}

export const tempSearchStateKey = 'temp'

export function useSearchValues(props: ProSearchProps): SearchValueContext {
const [searchValues, setSearchValues] = useControlledProp(props, 'value')
const searchValueEmpty = computed(() => !searchValues.value || searchValues.value.length <= 0)

return {
searchValues,
searchValueEmpty,
setSearchValues,
}
}

0 comments on commit ca4963c

Please sign in to comment.