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 dfbf4f7 commit 054bd93
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/modules/Dropdown/Dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -1169,7 +1169,7 @@ export default class Dropdown extends Component {
onClick: this.handleItemClick,
selected: selectedIndex === i,
...opt,
key: getKeyOrValue(key, value),
key: getKeyOrValue(opt.key, opt.value),
// Needed for handling click events on disabled items
style: { ...opt.style, pointerEvents: 'all' },
}))
Expand Down
14 changes: 14 additions & 0 deletions test/specs/modules/Dropdown/Dropdown-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1497,6 +1497,20 @@ describe('Dropdown', () => {
.find('DropdownItem')
.everyWhere(item => item.should.have.prop('data-foo', 'someValue'))
})

it('handles keys correctly', () => {
const customOptions = [
{ key: 0, text: 'foo', value: 'foo' },
{ key: null, text: 'bar', value: 'bar' },
{ key: undefined, text: 'baz', value: 'baz' },
]
const wrapper = wrapperMount(<Dropdown options={customOptions} selection />)
const items = wrapper.find('DropdownItem')

items.at(0).key().should.equal('0')
items.at(1).key().should.equal('bar')
items.at(2).key().should.equal('baz')
})
})

describe('selection', () => {
Expand Down

0 comments on commit 054bd93

Please sign in to comment.