MultiSelect: select values on blur

This commit is contained in:
Paul Chavard 2021-05-20 13:15:27 +02:00
parent 3313ea5885
commit bf462380e6

View file

@ -100,6 +100,17 @@ function ComboMultipleDropdownList({
} }
}; };
const onBlur = (event) => {
if (
acceptNewValues &&
term &&
[...extraOptions, ...options].map(([label]) => label).includes(term)
) {
event.preventDefault();
return onSelect(term);
}
};
const saveSelection = (fn) => { const saveSelection = (fn) => {
setSelections((selections) => { setSelections((selections) => {
selections = fn(selections); selections = fn(selections);
@ -162,6 +173,7 @@ function ComboMultipleDropdownList({
value={term} value={term}
onChange={handleChange} onChange={handleChange}
onKeyDown={onKeyDown} onKeyDown={onKeyDown}
onBlur={onBlur}
autocomplete={false} autocomplete={false}
/> />
</ComboboxTokenLabel> </ComboboxTokenLabel>