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 React, {useState, useRef} from 'react';
|
||||||
|
import * as diacritics from 'diacritics';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Codes des touches du clavier par nom.
|
* Codes des touches du clavier par nom.
|
||||||
|
@ -12,6 +13,19 @@ const keys = Object.assign(Object.create(null), {
|
||||||
'down': 40,
|
'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.
|
* Zone de saisie des termes de recherche.
|
||||||
*
|
*
|
||||||
|
@ -141,9 +155,7 @@ const TermInput = ({terms, availableTerms, setTerms}) =>
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
// Filtre ceux dont le nom correspond à la saisie
|
// Filtre ceux dont le nom correspond à la saisie
|
||||||
.filter(({name}) =>
|
.filter(termMatchesPrefix.bind(null, nextValue))
|
||||||
name.toLowerCase().startsWith(nextValue.toLowerCase())
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -2508,6 +2508,11 @@
|
||||||
"integrity": "sha1-l4hXRCxEdJ5CBmE+N5RiBYJqvYA=",
|
"integrity": "sha1-l4hXRCxEdJ5CBmE+N5RiBYJqvYA=",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"diacritics": {
|
||||||
|
"version": "1.3.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/diacritics/-/diacritics-1.3.0.tgz",
|
||||||
|
"integrity": "sha1-PvqHMj67hj5mls67AILUj/PW96E="
|
||||||
|
},
|
||||||
"diffie-hellman": {
|
"diffie-hellman": {
|
||||||
"version": "5.0.3",
|
"version": "5.0.3",
|
||||||
"resolved": "https://registry.npmjs.org/diffie-hellman/-/diffie-hellman-5.0.3.tgz",
|
"resolved": "https://registry.npmjs.org/diffie-hellman/-/diffie-hellman-5.0.3.tgz",
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@babel/runtime": "^7.7.4",
|
"@babel/runtime": "^7.7.4",
|
||||||
|
"diacritics": "^1.3.0",
|
||||||
"eslint": "^6.7.2",
|
"eslint": "^6.7.2",
|
||||||
"eslint-plugin-react": "^7.17.0",
|
"eslint-plugin-react": "^7.17.0",
|
||||||
"react": "^16.12.0",
|
"react": "^16.12.0",
|
||||||
|
|
Loading…
Reference in New Issue