From f85b4449ef1af14698665ab979305d7fd51b8fb2 Mon Sep 17 00:00:00 2001 From: AgentChris Date: Wed, 30 Aug 2017 17:45:44 +0300 Subject: [PATCH] feat(Dropdown): remove diacritics on filter (#2021) * 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 --- src/modules/Dropdown/Dropdown.js | 3 ++- test/specs/modules/Dropdown/Dropdown-test.js | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/modules/Dropdown/Dropdown.js b/src/modules/Dropdown/Dropdown.js index 8b0ea2a615..0b53ce8e4b 100644 --- a/src/modules/Dropdown/Dropdown.js +++ b/src/modules/Dropdown/Dropdown.js @@ -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))) } } diff --git a/test/specs/modules/Dropdown/Dropdown-test.js b/test/specs/modules/Dropdown/Dropdown-test.js index 456aae0ca4..9954bdc559 100644 --- a/test/specs/modules/Dropdown/Dropdown-test.js +++ b/test/specs/modules/Dropdown/Dropdown-test.js @@ -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() + .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' },