Skip to content

Commit

Permalink
feat(Dropdown): remove diacritics on filter (#2021)
Browse files Browse the repository at this point in the history
* remove diacritics on filter

* change to arrow function

* use lodash _.deburr instead

* added a test for filter after diacritics

* remove unnecessary ternary check

* remove unnecessary tests check on filter diacritics
  • Loading branch information
AgentChris authored and levithomason committed Aug 30, 2017
1 parent e1ff28a commit f85b444
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/modules/Dropdown/Dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -795,7 +795,8 @@ export default class Dropdown extends Component {
filteredOptions = search(filteredOptions, searchQuery)
} else {
const re = new RegExp(_.escapeRegExp(searchQuery), 'i')
filteredOptions = _.filter(filteredOptions, opt => re.test(opt.text))
// remove diacritics on search
filteredOptions = _.filter(filteredOptions, opt => re.test(_.deburr(opt.text)))
}
}

Expand Down
17 changes: 17 additions & 0 deletions test/specs/modules/Dropdown/Dropdown-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,23 @@ describe('Dropdown', () => {
.find('.selected')
.should.contain.text('a2')
})
it('filter after diacritics', () => {
const opts = [
{ text: 'FLOREŞTI', value: '1' },
{ text: 'ŞANŢU FLOREŞTI', value: '2' },
{ text: 'FLOREŞTI Alba', value: '3' },
]

// search for 'floresti'
wrapperMount(<Dropdown options={opts} search selection />)
.simulate('click')
.find('input.search')
.simulate('change', { target: { value: 'floresti' } })

wrapper
.find('.selected')
.should.contain.text('FLOREŞTI')
})
it('still works after encountering "no results"', () => {
const opts = [
{ text: 'a1', value: 'a1' },
Expand Down

0 comments on commit f85b444

Please sign in to comment.