Skip to content

Commit

Permalink
feat(select): retour review
Browse files Browse the repository at this point in the history
  • Loading branch information
juliebrunetto83 committed Jul 10, 2024
1 parent 8af996f commit e5a6bd4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@use "../../../../../styles/utilities-deprecated";
@use "../../../../../styles/utilities";
@use "../../../../../styles/components/form/variables";
@use "@styles/utilities-deprecated";
@use "@styles/utilities";
@use "@styles/components/form/variables";

.label {
@extend %label-champ;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useMemo } from 'react';
import React, { useCallback, useMemo } from 'react';
import { useRefinementList, UseRefinementListProps } from 'react-instantsearch';

import { getCapitalizedItems } from '~/client/components/ui/Meilisearch/getCapitalizedItems';
Expand All @@ -13,23 +13,25 @@ export function MeilisearchSelectMultiple(props: UseRefinementListProps & Meilis
const { label, className } = props;

// TODO (BRUJ 08/07/2024): A supprimer lors du passage des options en composition
const optionsList: Array<OptionSelect> = items.map((item) => ({
libellé: getCapitalizedItems(item.label),
valeur: item.value,
}));
const optionsList: Array<OptionSelect> = useMemo(() => {
return items.map((item) => ({
libellé: getCapitalizedItems(item.label),
valeur: item.value,
}));
}, [items]);

const valuesSelected = useMemo(() => {
return items.filter((item) => item.isRefined)
.map((item) => item.value);
}, [items]);


function onOptionSelected(option: HTMLElement) {
const value = option.getAttribute('data-value') ?? '';
value && refine(value);
}
const onOptionSelected = useCallback((option: HTMLElement) => {
const value = option.getAttribute('data-value');
if (value) refine(value);
}, [refine]);

return (
<Select className={className} label={label} optionList={optionsList} multiple onChange={onOptionSelected} value={valuesSelected}/>
<Select className={className} label={label} optionList={optionsList} multiple onChange={onOptionSelected}
value={valuesSelected}/>
);
}

0 comments on commit e5a6bd4

Please sign in to comment.