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

Conversation

AgentChris
Copy link
Contributor

I really need this feature, can you guys help me?

@@ -795,7 +795,14 @@ 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))
filteredOptions = _.filter(filteredOptions, function (opt) {
Copy link
Member

@levithomason levithomason Aug 29, 2017

Choose a reason for hiding this comment

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

This should just be:

-filteredOptions = _.filter(filteredOptions, opt => re.test(opt.text))
+filteredOptions = _.filter(filteredOptions, opt => re.test(_.deburr(opt.text)))

https://lodash.com/docs/4.17.4#deburr

@levithomason
Copy link
Member

See inline comment on _.deburr. We just need a test case for this now. See Dropdown-test.js.

@AgentChris
Copy link
Contributor Author

AgentChris commented Aug 29, 2017

for example when i have this options:
when i search after: floresti
i will get no response, but when i click outside i can view the options

rsz_1screenshot_from_2017-08-29_19-53-59

rsz_1screenshot_from_2017-08-29_19-54-07

@levithomason
Copy link
Member

Yep, I'm noting we should use lodash's _.deburr method rather than writing our own filter:

image

@AgentChris
Copy link
Contributor Author

ty for your quick response, i will try to add a test, first time I am doing a pull request so please have patience :)

@codecov-io
Copy link

codecov-io commented Aug 29, 2017

Codecov Report

Merging #2021 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #2021   +/-   ##
=======================================
  Coverage   99.76%   99.76%           
=======================================
  Files         148      148           
  Lines        2556     2556           
=======================================
  Hits         2550     2550           
  Misses          6        6
Impacted Files Coverage Δ
src/modules/Dropdown/Dropdown.js 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e1ff28a...f93870d. Read the comment docs.

@@ -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


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. 👍

@levithomason
Copy link
Member

Awesome, congrats on your first PR :) I left a couple more comments, then I think we're ready to go here.

@levithomason
Copy link
Member

Be sure to run npm run lint:fix as well. This will run lint checks and also fix some issues for you. You can ignore the warnings, but the errors will need fixed. This one was failing CI:

/home/ubuntu/Semantic-UI-React/src/modules/Dropdown/Dropdown.js
  799:97  error  Infix operators must be spaced  space-infix-ops

@AgentChris
Copy link
Contributor Author

AgentChris commented Aug 29, 2017

hey i've made the changes, i hope they are good, thank you soooo much for your help, i am going to brag all day to my work colleagues :))) good job on this library 👍

@layershifter layershifter changed the title remove diacritics on filter feat(Dropdown): remove diacritics on filter Aug 30, 2017
@levithomason levithomason merged commit f85b444 into Semantic-Org:master Aug 30, 2017
@levithomason
Copy link
Member

Thanks! Nice work, brag away my friend :)

@AgentChris AgentChris deleted the feat/searchWithoutDiacritics branch August 30, 2017 15:34
layershifter pushed a commit that referenced this pull request Aug 31, 2017
* 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
@levithomason
Copy link
Member

Released in semantic-ui-react@0.73.0

layershifter pushed a commit that referenced this pull request Sep 11, 2017
* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants