Skip to content

Commit

Permalink
fix(pro:search): selecting option after remote search overides value (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
sallerli1 committed Jun 11, 2024
1 parent d64929f commit 708f1f7
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions packages/pro/search/src/segments/CreateSelectSegment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export function createSelectSegment(
name: 'select',
inputClassName: [`${prefixCls}-select-segment-input`],
containerClassName: [`${prefixCls}-select-segment-container`],
parse: input => parseInput(input, config, locale.allSelected),
parse: (input, _, getCacheData) => parseInput(input, config, locale.allSelected, getCacheData),
format: (value, states, getCacheData, setCacheData) =>
formatValue(value, states, getCacheData, setCacheData, config, locale.allSelected),
panelRenderer,
Expand All @@ -81,14 +81,18 @@ function parseInput(
input: string,
config: SelectSearchField['fieldConfig'],
allSelected: string,
getCacheData: (dataKey: string) => any,
): VKey | VKey[] | undefined {
const { concludeAllSelected, separator, dataSource, multiple } = config
const trimedInput = input.trim()

const cachedData = getCacheData(dataSourceCacheKey)
const mergedDataSource = cachedData ? mergeData(cachedData, dataSource) : dataSource

const keys =
concludeAllSelected && trimedInput === allSelected
? dataSource.map(data => data.key)
: getKeyByLabels(dataSource, trimedInput.split(separator ?? defaultSeparator))
? mergedDataSource.map(data => data.key)
: getKeyByLabels(mergedDataSource, trimedInput.split(separator ?? defaultSeparator))

return multiple ? (keys.length > 0 ? keys : undefined) : keys[0]
}
Expand Down

0 comments on commit 708f1f7

Please sign in to comment.