app: Recherche ignore les accents
This commit is contained in:
		
							parent
							
								
									99a2d487f3
								
							
						
					
					
						commit
						eea5e49a96
					
				|  | @ -1,4 +1,5 @@ | |||
| import React, {useState, useRef} from 'react'; | ||||
| import * as diacritics from 'diacritics'; | ||||
| 
 | ||||
| /** | ||||
|  * Codes des touches du clavier par nom. | ||||
|  | @ -12,6 +13,19 @@ const keys = Object.assign(Object.create(null), { | |||
|     'down': 40, | ||||
| }); | ||||
| 
 | ||||
| /** | ||||
|  * Vérifie si un terme est similaire à un préfixe saisi. | ||||
|  * | ||||
|  * @param prefix Préfixe saisi. | ||||
|  * @param term Terme à vérifier. | ||||
|  * @return Vrai si le terme est considéré comme similaire au préfixe. | ||||
|  */ | ||||
| const termMatchesPrefix = (prefix, {name}) => | ||||
| { | ||||
|     return diacritics.remove(name.toLowerCase()) | ||||
|         .startsWith(diacritics.remove(prefix.toLowerCase())); | ||||
| }; | ||||
| 
 | ||||
| /** | ||||
|  * Zone de saisie des termes de recherche. | ||||
|  * | ||||
|  | @ -141,9 +155,7 @@ const TermInput = ({terms, availableTerms, setTerms}) => | |||
|                     ) | ||||
|                 ) | ||||
|                 // Filtre ceux dont le nom correspond à la saisie
 | ||||
|                 .filter(({name}) => | ||||
|                     name.toLowerCase().startsWith(nextValue.toLowerCase()) | ||||
|                 ) | ||||
|                 .filter(termMatchesPrefix.bind(null, nextValue)) | ||||
|             ); | ||||
|         } | ||||
|     }; | ||||
|  |  | |||
|  | @ -2508,6 +2508,11 @@ | |||
|       "integrity": "sha1-l4hXRCxEdJ5CBmE+N5RiBYJqvYA=", | ||||
|       "dev": true | ||||
|     }, | ||||
|     "diacritics": { | ||||
|       "version": "1.3.0", | ||||
|       "resolved": "https://registry.npmjs.org/diacritics/-/diacritics-1.3.0.tgz", | ||||
|       "integrity": "sha1-PvqHMj67hj5mls67AILUj/PW96E=" | ||||
|     }, | ||||
|     "diffie-hellman": { | ||||
|       "version": "5.0.3", | ||||
|       "resolved": "https://registry.npmjs.org/diffie-hellman/-/diffie-hellman-5.0.3.tgz", | ||||
|  |  | |||
|  | @ -16,6 +16,7 @@ | |||
|   }, | ||||
|   "dependencies": { | ||||
|     "@babel/runtime": "^7.7.4", | ||||
|     "diacritics": "^1.3.0", | ||||
|     "eslint": "^6.7.2", | ||||
|     "eslint-plugin-react": "^7.17.0", | ||||
|     "react": "^16.12.0", | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue