Skip to content

Commit 72e2e3f

Browse files
author
Vikas Agarwal
committed
Github issue #317 [Specification] - no option to remove the color added
-- Fixed the edge case bug where user wasn't able to add new colors even if he/she has removed colors after max limit reached. -- Removed colors state variable as it is not needed now because we don't have enable/disable kind of behaviour.
1 parent dd3d230 commit 72e2e3f

File tree

1 file changed

+5
-11
lines changed

1 file changed

+5
-11
lines changed

src/components/ColorSelector/ColorSelector.jsx

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,14 @@ class ColorSelector extends React.Component {
1313

1414
this.state = {
1515
isPickerVisible: false,
16-
newColor: '#fff',
17-
colors: _.uniq([...props.defaultColors, ...props.value])
16+
newColor: '#fff'
1817
}
1918
}
2019

2120
render() {
22-
const {getValue, name, onChange, setValue} = this.props
23-
const value = getValue() || []
24-
const {isPickerVisible, colors, newColor} = this.state
21+
const {getValue, name, onChange, setValue, defaultColors } = this.props
22+
const value = getValue() || defaultColors
23+
const {isPickerVisible, newColor} = this.state
2524

2625
const onColorToggle = (color) => {
2726
const index = value.indexOf(color)
@@ -54,7 +53,7 @@ class ColorSelector extends React.Component {
5453
</a>
5554
)}
5655

57-
{colors.length < PROJECT_MAX_COLORS &&
56+
{value.length < PROJECT_MAX_COLORS &&
5857
<a
5958
href="javascript:"
6059
onClick={() => this.setState({isPickerVisible: true})}
@@ -72,11 +71,6 @@ class ColorSelector extends React.Component {
7271
<button type="button" className="tc-btn tc-btn-primary tc-btn-md"
7372
onClick={() => {
7473
this.setState({isPickerVisible: false})
75-
if (colors.indexOf(newColor) === -1) {
76-
this.setState({colors: [...colors, newColor], newColor: '#fff'})
77-
} else {
78-
this.setState({newColor: '#fff'})
79-
}
8074
const newValue = [...value, newColor]
8175
setValue(newValue)
8276
onChange(name, newValue)

0 commit comments

Comments
 (0)