Skip to content

Commit

Permalink
feat(Dropdown): custom "No results" message (#416) (#417)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffcarbs authored and levithomason committed Aug 22, 2016
1 parent 03cb9a5 commit 25bf913
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/modules/Dropdown/Dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ export default class Dropdown extends Component {
/** Label prefixed to an option added by a user. */
additionLabel: PropTypes.string,

/** Message to display when there are no results. */
noResultsMessage: PropTypes.string,

// ------------------------------------
// Callbacks
// ------------------------------------
Expand Down Expand Up @@ -197,6 +200,7 @@ export default class Dropdown extends Component {
static defaultProps = {
icon: 'dropdown',
additionLabel: 'Add:',
noResultsMessage: 'No results found.',
}

static autoControlledProps = [
Expand Down Expand Up @@ -770,12 +774,12 @@ export default class Dropdown extends Component {
}

renderOptions = () => {
const { multiple, search } = this.props
const { multiple, search, noResultsMessage } = this.props
const { selectedIndex, value } = this.state
const options = this.getMenuOptions()

if (search && _.isEmpty(options)) {
return <div className='message'>No results found.</div>
return <div className='message'>{noResultsMessage}</div>
}

const isActive = multiple
Expand Down
36 changes: 36 additions & 0 deletions test/specs/modules/Dropdown/Dropdown-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1010,6 +1010,42 @@ describe('Dropdown Component', () => {
.find('.message')
.should.not.be.present()
})

it('uses default noResultsMessage', () => {
const search = wrapperMount(<Dropdown options={options} selection search />)
.find('input.search')

// search for something we know will not exist
search.simulate('change', { target: { value: '_________________' } })

wrapper
.find('.message')
.should.have.text('No results found.')
})

it('uses custom noResultsMessage', () => {
const search = wrapperMount(<Dropdown options={options} selection search noResultsMessage='Something custom' />)
.find('input.search')

// search for something we know will not exist
search.simulate('change', { target: { value: '_________________' } })

wrapper
.find('.message')
.should.have.text('Something custom')
})

it('uses no noResultsMessage', () => {
const search = wrapperMount(<Dropdown options={options} selection search noResultsMessage='' />)
.find('input.search')

// search for something we know will not exist
search.simulate('change', { target: { value: '_________________' } })

wrapper
.find('.message')
.should.have.text('')
})
})

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

0 comments on commit 25bf913

Please sign in to comment.