Skip to content

Commit 0e16fdd

Browse files
Fix tag multi select reset on click
1 parent b413139 commit 0e16fdd

File tree

4 files changed

+27
-1
lines changed

4 files changed

+27
-1
lines changed

app/javascript/tagging/components/InnerComponents/ValueModifier.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import ValueSelector from './ValueSelector';
55
import TaggingPropTypes from '../TaggingPropTypes';
66

77
const ValueModifier = ({
8+
selectedTagCategory,
89
values,
910
onTagValueChange,
1011
selectedTagValues,
@@ -15,6 +16,7 @@ const ValueModifier = ({
1516
<FormGroup legendText={valueLabel}>
1617
<Column className="tag-modifier-form-row value-modifier">
1718
<ValueSelector
19+
selectedTagCategory={selectedTagCategory}
1820
values={values}
1921
onTagValueChange={onTagValueChange}
2022
selectedOption={selectedTagValues}
@@ -26,6 +28,7 @@ const ValueModifier = ({
2628
);
2729

2830
ValueModifier.propTypes = {
31+
selectedTagCategory: PropTypes.string.isRequired,
2932
selectedTagValues: PropTypes.arrayOf(TaggingPropTypes.value),
3033
onTagValueChange: PropTypes.func.isRequired,
3134
valueLabel: PropTypes.string,

app/javascript/tagging/components/InnerComponents/ValueSelector.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ class ValueSelector extends React.Component {
102102
label={label}
103103
initialSelectedItems={selectedOptions}
104104
// eslint-disable-next-line react/destructuring-assignment
105-
key={selectedOptions.length === 0 ? -1 : this.props.values[0].id + selectedOptions.length}
105+
key={this.props.selectedTagCategory.description}
106106
items={values}
107107
disabled={isDisabled}
108108
onChange={(val) => this.handleChange(val)}
@@ -135,6 +135,10 @@ class ValueSelector extends React.Component {
135135
}
136136

137137
ValueSelector.propTypes = {
138+
selectedTagCategory: PropTypes.objectOf({
139+
id: PropTypes.string.isRequired,
140+
description: PropTypes.string.isRequired,
141+
}).isRequired,
138142
selectedOption: PropTypes.arrayOf(TaggingPropTypes.value),
139143
values: PropTypes.arrayOf(TaggingPropTypes.value).isRequired,
140144
onTagValueChange: PropTypes.func.isRequired,

app/javascript/tagging/components/Tagging/Tagging.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ class Tagging extends React.Component {
7676
isDisabled={isDisabled}
7777
/>
7878
<ValueModifier
79+
selectedTagCategory={selectedTagCategory}
7980
onTagValueChange={this.onTagValueChange}
8081
selectedTagValues={this.getSelectedCategoryValues().values}
8182
multiValue={this.isMulti(selectedTagCategory)}

app/javascript/tagging/tests/__snapshots__/tagging.test.js.snap

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ exports[`Tagging component without redux mapping match snapshot 1`] = `
5555
isDisabled={false}
5656
multiValue={true}
5757
onTagValueChange={[Function]}
58+
selectedTagCategory={
59+
Object {
60+
"description": "animal",
61+
"id": 1,
62+
}
63+
}
5864
selectedTagValues={
5965
Array [
6066
Object {
@@ -161,6 +167,12 @@ exports[`Tagging component without redux mapping should call methods - singleVal
161167
isDisabled={false}
162168
multiValue={true}
163169
onTagValueChange={[Function]}
170+
selectedTagCategory={
171+
Object {
172+
"description": "Food",
173+
"id": 4,
174+
}
175+
}
164176
selectedTagValues={Array []}
165177
valueLabel="Value"
166178
values={
@@ -264,6 +276,12 @@ exports[`Tagging component without redux mapping should call methods - singleVal
264276
isDisabled={false}
265277
multiValue={false}
266278
onTagValueChange={[Function]}
279+
selectedTagCategory={
280+
Object {
281+
"description": "Something",
282+
"id": 5,
283+
}
284+
}
267285
selectedTagValues={Array []}
268286
valueLabel="Value"
269287
values={

0 commit comments

Comments
 (0)