Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Dropdown): remove diacritics on filter #2021

Merged
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(opt.text ? _.deburr(opt.text): opt.text))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lodash gracefully handles null and undefined values, so you can safely remove the ternary check here. The method will always return a string:

image

}
}

Expand Down
31 changes: 31 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,37 @@ 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')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great. We can end the test here as one assertion is enough to prove the feature.

Skipping the additional arrow down behaviors will make this test stronger. This way, the filter after diacritics test doesn't fail if the arrow down behavior changes, but only if the search filter behavior changes. 👍


// move selection down
domEvent.keyDown(document, { key: 'ArrowDown' })

wrapper
.find('.selected')
.should.contain.text('ŞANŢU FLOREŞTI')

// move selection down
domEvent.keyDown(document, { key: 'ArrowDown' })

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