feat: 评分组件 texts、colors 过滤非数字key, 如:$$id

This commit is contained in:
liuzedong02 2022-04-15 17:05:36 +08:00
parent 4f9395fb3b
commit addbc69fd7

View File

@ -138,9 +138,12 @@ export class Rating extends React.Component<RatingProps, any> {
const showKey = keys.filter(item => Number(item) < value).length;
const showColor = keys[showKey] !== undefined && colors[keys[showKey]];
// 取最大 key 的颜色避免如下情况colors 只设置了 1-4value 为 5导致取不到颜色而无法显示
const lastColor = keys.length && colors[keys[keys.length - 1]];
this.setState({
showColor: showColor || ''
showColor: showColor || lastColor || ''
});
} else if (colors && typeof colors === 'string') {
this.setState({