fix: inputText autoComplete 输入内容导致选项重复问题 (#5272)

* fix: inputText autoComplete 输入内容导致选项重复问题

* 修改
This commit is contained in:
sansiro 2022-09-15 19:28:08 +08:00 committed by GitHub
parent 1eb03d6a79
commit 92d08b0ae4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,14 +1,20 @@
import {OptionValue, Option} from '../types';
import {isObject} from './helper';
import {isEqual} from 'lodash';
export function matchOptionValue(
a: OptionValue,
b: Option,
valueField: string = 'value'
) {
return isObject(a)
? a === b[valueField || 'value']
: String(b[valueField || 'value']) === String(a);
// a 可能为 Option, 此时需要取其value
const aValue =
isObject(a) && a && (a as Option).hasOwnProperty(valueField)
? (a as Option)[valueField]
: a;
return isObject(aValue)
? isEqual(aValue, b[valueField || 'value'])
: String(b[valueField || 'value']) === String(aValue);
}
export function optionValueCompare(