Skip to content

Commit

Permalink
Fix normalize sur l'autocomplete pour utiliser une fonction native
Browse files Browse the repository at this point in the history
  • Loading branch information
JabX committed Jan 15, 2024
1 parent bce0f0f commit cb96c9f
Showing 1 changed file with 8 additions and 18 deletions.
26 changes: 8 additions & 18 deletions packages/toolbox/src/components/autocomplete.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ export const Autocomplete = forwardRef(function Autocomplete<TSource = {key: str

// Suggestions.
const suggestions = useMemo(() => {
const newQuery = normalise(`${query}`);
const newQuery = normalize(`${query}`);

/** Détermine si la valeur est une match pour la requête. */
function isMatch(v: string, q: string) {
Expand All @@ -195,7 +195,7 @@ export const Autocomplete = forwardRef(function Autocomplete<TSource = {key: str
}

if (newQuery) {
return values.filter(v => isMatch(normalise(getLabel(v)), newQuery));
return values.filter(v => isMatch(normalize(getLabel(v)), newQuery));
} else {
return values;
}
Expand Down Expand Up @@ -376,20 +376,10 @@ export const Autocomplete = forwardRef(function Autocomplete<TSource = {key: str
props: AutocompleteProps<TSource> & {ref?: React.ForwardedRef<HTMLInputElement | HTMLTextAreaElement>}
) => ReactElement;

function normalise(value: string) {
const sdiak =
"áâäąáâäąččććççĉĉďđďđééěëēėęéěëēėęĝĝğğġġģģĥĥħħíîíîĩĩīīĭĭįįi̇ıĵĵķķĸĺĺļļŀŀłłĺľĺľňńņŋŋņňńʼnóöôőøōōóöőôøřřŕŕŗŗššśśŝŝşşţţťťŧŧũũūūŭŭůůűűúüúüűųųŵŵýyŷŷýyžžźźżżß";
const bdiak =
"AAAAAAAACCCCCCCCDDDDEEEEEEEEEEEEEGGGGGGGGHHHHIIIIIIIIIIIIIIJJKKKLLLLLLLLLLLLNNNNNNNNNOOOOOOOOOOOORRRRRRSSSSSSSSTTTTTTUUUUUUUUUUUUUUUUUWWYYYYYYZZZZZZS";

let normalised = "";
for (let p = 0; p < value.length; p++) {
if (sdiak.includes(value.charAt(p))) {
normalised += bdiak.charAt(sdiak.indexOf(value.charAt(p)));
} else {
normalised += value.charAt(p);
}
}

return normalised.toLowerCase().trim();
function normalize(value: string) {
return value
.normalize("NFD")
.replace(/\p{Diacritic}/gu, "")
.toLowerCase()
.trim();
}

0 comments on commit cb96c9f

Please sign in to comment.