Skip to content

Commit 53b90ff

Browse files
committed
fix(color-setter): 优化颜色设置器的值处理逻辑
- 将 setterValue 的类型从 string 改为 string | null,以支持 null 值 - 在渲染时使用 value = setterValue || undefined,确保不接收 null 作为值 - 更新 Input 和 SketchPicker 组件的 value 属性,以适应新的值处理逻辑
1 parent da39483 commit 53b90ff

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/setter/color-setter/index.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@ import * as React from 'react';
22
import { Input, Balloon } from '@alifd/next';
33
import { SketchPicker } from 'react-color';
44
import './index.less';
5+
56
interface ColorSetterProps {
67
value: string;
78
onChange: (val: any) => void;
89
defaultValue: string;
910
}
1011
interface ColorSetterState {
1112
width: number;
12-
setterValue: string;
13+
setterValue: string | null;
1314
}
1415
export default class ColorSetter extends React.Component<ColorSetterProps, ColorSetterState> {
1516
static displayName = 'ColorSetter';
@@ -66,13 +67,17 @@ export default class ColorSetter extends React.Component<ColorSetterProps, Color
6667
render() {
6768
const { width, setterValue } = this.state;
6869
const { onChange } = this.props;
70+
71+
// 不接收null作为值
72+
const value = setterValue || undefined;
73+
6974
const InputTarget = (
7075
<Input
7176
size="small"
7277
className="lowcode-setter-color"
7378
style={{ width: '100%' }}
74-
innerBefore={<div className="color-box" style={{ backgroundColor: setterValue }} />}
75-
value={setterValue}
79+
innerBefore={<div className="color-box" style={{ backgroundColor: value }} />}
80+
value={(setterValue ?? '') as string}
7681
onChange={onChange}
7782
/>
7883
);
@@ -86,7 +91,7 @@ export default class ColorSetter extends React.Component<ColorSetterProps, Color
8691
triggerType="click"
8792
closable={false}
8893
>
89-
<SketchPicker color={setterValue} onChange={this.handleChange} />
94+
<SketchPicker color={value} onChange={this.handleChange} />
9095
</Balloon>
9196
);
9297
}

0 commit comments

Comments
 (0)