Skip to content

Commit

Permalink
Merge pull request #1401 from Amadey666/master
Browse files Browse the repository at this point in the history
Fixed #1397 - duplicate key error in listbox and dropdown
  • Loading branch information
mertsincan authored Jun 24, 2020
2 parents 4047cc3 + 7a44453 commit b162ac8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
10 changes: 6 additions & 4 deletions src/components/dropdown/Dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -616,10 +616,12 @@ export class Dropdown extends Component {
}

if (items) {
return items.map((option) => {
return items.map((option, index) => {
let optionLabel = this.getOptionLabel(option);
let optionKey = this.getOptionKey(option, index);

return (
<DropdownItem key={this.getOptionKey(option)} label={optionLabel} option={option} template={this.props.itemTemplate} selected={selectedOption === option} disabled={option.disabled} onClick={this.onOptionClick} />
<DropdownItem key={optionKey} label={optionLabel} option={option} template={this.props.itemTemplate} selected={selectedOption === option} disabled={option.disabled} onClick={this.onOptionClick} />
);
});
}
Expand Down Expand Up @@ -649,8 +651,8 @@ export class Dropdown extends Component {
return this.props.optionValue ? ObjectUtils.resolveFieldData(option, this.props.optionValue) : (option['value'] !== undefined ? option['value'] : option);
}

getOptionKey(option) {
return this.props.dataKey ? ObjectUtils.resolveFieldData(option, this.props.dataKey) : this.getOptionLabel(option);
getOptionKey(option, index) {
return this.props.dataKey ? ObjectUtils.resolveFieldData(option, this.props.dataKey) : `pr_id__${this.getOptionLabel}-${index}`;
}

checkValidity() {
Expand Down
3 changes: 2 additions & 1 deletion src/components/listbox/ListBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,9 +278,10 @@ export class ListBox extends Component {

items = items.map((option, index) => {
let optionLabel = this.getOptionLabel(option);
let optionKey = `pr_id__${optionLabel}-${index}`;

return (
<ListBoxItem key={optionLabel} label={optionLabel} option={option} template={this.props.itemTemplate} selected={this.isSelected(option)}
<ListBoxItem key={optionKey} label={optionLabel} option={option} template={this.props.itemTemplate} selected={this.isSelected(option)}
onClick={this.onOptionClick} onTouchEnd={(e) => this.onOptionTouchEnd(e, option, index)} tabIndex={this.props.tabIndex} />
);
});
Expand Down

0 comments on commit b162ac8

Please sign in to comment.