Skip to content

Commit

Permalink
fix: scale 初始填充问题 (#72)
Browse files Browse the repository at this point in the history
Co-authored-by: yxh01132861 <[email protected]>
Co-authored-by: lvisei <[email protected]>
  • Loading branch information
3 people authored Nov 8, 2023
1 parent 7516d77 commit 3ca0cef
Showing 1 changed file with 16 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,19 +76,25 @@ const Internal = (props: ScaleSelectorProp) => {

// dataType 变更,引起可选类型变更,当 scale 为非自定义时自动填充当前类型
useEffect(() => {
if (!value) return;
// 非自定义数据
if (!value.isCustom) {
let defaultSelectType: SelectType | undefined;

// 初始,scale 填入默认值
if (!value) {
defaultSelectType = selectOptions[0].value;
// 非自定义数据情况
} else if (!value.isCustom) {
// 判断 value 类型是否有效
const isValid = selectOptions.findIndex((item) => item.value === value.type) === -1;
if (isValid) {
const val = selectOptions[0].value !== 'custom' ? selectOptions[0].value : undefined;
setSelectedType(val);
if (val) {
onChange?.({ isCustom: false, type: val });
}
const isValid = selectOptions.some((item) => item.value === value.type);
if (!isValid) {
defaultSelectType = selectOptions[0].value;
}
}

// 设置默认选中类型;因类型推断问题,当前传入类型去除 custom
if (defaultSelectType && defaultSelectType !== 'custom') {
setSelectedType(defaultSelectType);
onChange?.({ isCustom: false, type: defaultSelectType });
}
}, [selectOptions]);

// 自定义 scale 且数据 domain 发生更新时,自动计算默认值
Expand Down

0 comments on commit 3ca0cef

Please sign in to comment.