Skip to content

Commit

Permalink
fix(Dropdown): fix key handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Fedyashov committed Jun 1, 2017
1 parent 1a1b9e0 commit dfbf4f7
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/modules/Dropdown/Dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import DropdownMenu from './DropdownMenu'

const debug = makeDebugger('dropdown')

const getKeyOrValue = (key, value) => _.isNil(key) ? value : key

/**
* A dropdown allows a user to select a value from a series of options.
* @see Form
Expand Down Expand Up @@ -1071,7 +1073,7 @@ export default class Dropdown extends Component {
<select type='hidden' aria-hidden='true' name={name} value={value} multiple={multiple}>
<option value='' />
{_.map(options, (option, i) => (
<option key={option.key || option.value} value={option.value}>{option.text}</option>
<option key={getKeyOrValue(option.key, option.value)} value={option.value}>{option.text}</option>
))}
</select>
)
Expand Down Expand Up @@ -1136,7 +1138,7 @@ export default class Dropdown extends Component {
const defaultProps = {
active: item.value === selectedLabel,
as: 'a',
key: item.key || item.value,
key: getKeyOrValue(item.key, item.value),
onClick: this.handleLabelClick,
onRemove: this.handleLabelRemove,
value: item.value,
Expand Down Expand Up @@ -1167,6 +1169,7 @@ export default class Dropdown extends Component {
onClick: this.handleItemClick,
selected: selectedIndex === i,
...opt,
key: getKeyOrValue(key, value),
// Needed for handling click events on disabled items
style: { ...opt.style, pointerEvents: 'all' },
}))
Expand Down

0 comments on commit dfbf4f7

Please sign in to comment.