@@ -2,14 +2,15 @@ import * as React from 'react';
22import { Input , Balloon } from '@alifd/next' ;
33import { SketchPicker } from 'react-color' ;
44import './index.less' ;
5+
56interface ColorSetterProps {
67 value : string ;
78 onChange : ( val : any ) => void ;
89 defaultValue : string ;
910}
1011interface ColorSetterState {
1112 width : number ;
12- setterValue : string ;
13+ setterValue : string | null ;
1314}
1415export 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