Skip to content

Commit 09ad5e0

Browse files
author
vikasrohit
authored
Merge pull request #524 from appirio-tech/feature/incosistent-max-colors-limit
Github issue #317 [Specification] - no option to remove the color added
2 parents 2fa6821 + 7cb5994 commit 09ad5e0

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/components/ColorSelector/ColorSelector.jsx

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ class ColorSelector extends React.Component {
2121
const value = getValue() || defaultColors
2222
const {isPickerVisible, newColor} = this.state
2323

24+
const updateNewColorPalette = (palette) => {
25+
setValue(palette)
26+
onChange(name, palette)
27+
}
28+
2429
const onColorToggle = (color) => {
2530
const index = value.indexOf(color)
2631
let newValue
@@ -32,8 +37,7 @@ class ColorSelector extends React.Component {
3237
newValue = tmp
3338
}
3439

35-
setValue(newValue)
36-
onChange(name, newValue)
40+
updateNewColorPalette(newValue)
3741
}
3842

3943
return (
@@ -51,7 +55,7 @@ class ColorSelector extends React.Component {
5155
</span>
5256
</a>
5357
)}
54-
58+
5559
{value.length < PROJECT_MAX_COLORS &&
5660
<a
5761
href="javascript:"
@@ -70,9 +74,11 @@ class ColorSelector extends React.Component {
7074
<button type="button" className="tc-btn tc-btn-primary tc-btn-md"
7175
onClick={() => {
7276
this.setState({isPickerVisible: false})
73-
const newValue = [...value, newColor]
74-
setValue(newValue)
75-
onChange(name, newValue)
77+
const index = value.indexOf(this.state.newColor)
78+
if (index === -1) {
79+
const newValue = [ ...value, newColor ]
80+
updateNewColorPalette(newValue)
81+
}
7682
}}
7783
>Add</button>
7884
<button

0 commit comments

Comments
 (0)