Skip to content

Commit

Permalink
fix(Dropdown): add addition item key (#1727)
Browse files Browse the repository at this point in the history
  • Loading branch information
levithomason authored Jun 1, 2017
1 parent 5539d49 commit bcc9482
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
5 changes: 3 additions & 2 deletions src/modules/Dropdown/Dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -759,15 +759,16 @@ export default class Dropdown extends Component {
// insert the "add" item
if (allowAdditions && search && searchQuery && !_.some(filteredOptions, { text: searchQuery })) {
const additionLabelElement = React.isValidElement(additionLabel)
? React.cloneElement(additionLabel, { key: 'label' })
? React.cloneElement(additionLabel, { key: 'addition-label' })
: additionLabel || ''

const addItem = {
key: 'addition',
// by using an array, we can pass multiple elements, but when doing so
// we must specify a `key` for React to know which one is which
text: [
additionLabelElement,
<b key='addition'>{searchQuery}</b>,
<b key='addition-query'>{searchQuery}</b>,
],
value: searchQuery,
className: 'addition',
Expand Down
8 changes: 4 additions & 4 deletions test/specs/modules/Dropdown/Dropdown-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1970,7 +1970,7 @@ describe('Dropdown', () => {
.prop('text')

expect(text[0]).to.equal('Add ')
shallow(text[1]).equals(<b key='addition'>boo</b>)
shallow(text[1]).equals(<b key='addition-query'>boo</b>)
})

it('uses custom additionLabel string', () => {
Expand All @@ -1995,7 +1995,7 @@ describe('Dropdown', () => {
.prop('text')

expect(text[0]).to.equal('New: ')
shallow(text[1]).equals(<b key='addition'>boo</b>)
shallow(text[1]).equals(<b key='addition-query'>boo</b>)
})

it('uses custom additionLabel element', () => {
Expand All @@ -2020,7 +2020,7 @@ describe('Dropdown', () => {
.prop('text')

shallow(text[0]).equals(<i key='label'>New: </i>)
shallow(text[1]).equals(<b key='addition'>boo</b>)
shallow(text[1]).equals(<b key='addition-query'>boo</b>)
})

it('uses no additionLabel', () => {
Expand All @@ -2045,7 +2045,7 @@ describe('Dropdown', () => {
.prop('text')

expect(text[0]).to.equal('')
shallow(text[1]).equals(<b key='addition'>boo</b>)
shallow(text[1]).equals(<b key='addition-query'>boo</b>)
})

it('keeps custom value option (bottom) when options change', () => {
Expand Down

0 comments on commit bcc9482

Please sign in to comment.