Skip to content

Commit

Permalink
fix(Dropdown): prefer item.key when rendering labels
Browse files Browse the repository at this point in the history
  • Loading branch information
David Zukowski committed May 10, 2017
1 parent 896ed31 commit 04ef42b
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 23 deletions.
2 changes: 1 addition & 1 deletion src/modules/Dropdown/Dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -1124,7 +1124,7 @@ export default class Dropdown extends Component {
const defaultProps = {
active: item.value === selectedLabel,
as: 'a',
key: item.value,
key: item.key || item.value,
onClick: this.handleLabelClick,
onRemove: this.handleLabelRemove,
value: item.value,
Expand Down
22 changes: 0 additions & 22 deletions test/specs/modules/Dropdown/Dropdown-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1835,28 +1835,6 @@ describe('Dropdown', () => {
})
})

describe('renderOptions', () => {
it('prefers the option\'s "key" property for keying generated DropdownItems', () => {
const customOptions = [
{ text: '1', value: '1', key: 'a' },
{ text: '2', value: '2', key: 'b' },
]
wrapperShallow(<Dropdown options={customOptions} />)
wrapper.should.contain('DropdownItem[key="a"]')
wrapper.should.contain('DropdownItem[key="b"]')
})

it('generates a "key" property using the option.value if no key is provided', () => {
const customOptions = [
{ text: '1', value: '1' },
{ text: '2', value: '2' },
]
wrapperShallow(<Dropdown options={customOptions} />)
wrapper.should.contain('DropdownItem[key="1-0"]')
wrapper.should.contain('DropdownItem[key="2-1"]')
})
})

describe('Dropdown.Menu child', () => {
it('renders child passed', () => {
wrapperShallow(
Expand Down

0 comments on commit 04ef42b

Please sign in to comment.