|
|
@ -26,17 +26,15 @@ export const Chips: FunctionComponent<ChipsProps> = ({
|
|
|
|
|
|
|
|
|
|
|
|
const input = useRef<HTMLInputElement>(null);
|
|
|
|
const input = useRef<HTMLInputElement>(null);
|
|
|
|
|
|
|
|
|
|
|
|
const changeRef = useRef(onChange);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const addChip = useCallback(
|
|
|
|
const addChip = useCallback(
|
|
|
|
(value: string) => {
|
|
|
|
(value: string) => {
|
|
|
|
setChips((cp) => {
|
|
|
|
setChips((cp) => {
|
|
|
|
const newChips = [...cp, value];
|
|
|
|
const newChips = [...cp, value];
|
|
|
|
changeRef.current && changeRef.current(newChips);
|
|
|
|
onChange && onChange(newChips);
|
|
|
|
return newChips;
|
|
|
|
return newChips;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
},
|
|
|
|
[changeRef]
|
|
|
|
[onChange]
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
const removeChip = useCallback(
|
|
|
|
const removeChip = useCallback(
|
|
|
@ -46,14 +44,14 @@ export const Chips: FunctionComponent<ChipsProps> = ({
|
|
|
|
if (index !== -1) {
|
|
|
|
if (index !== -1) {
|
|
|
|
const newChips = [...cp];
|
|
|
|
const newChips = [...cp];
|
|
|
|
newChips.splice(index, 1);
|
|
|
|
newChips.splice(index, 1);
|
|
|
|
changeRef.current && changeRef.current(newChips);
|
|
|
|
onChange && onChange(newChips);
|
|
|
|
return newChips;
|
|
|
|
return newChips;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
return cp;
|
|
|
|
return cp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
},
|
|
|
|
[changeRef]
|
|
|
|
[onChange]
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
const clearInput = useCallback(() => {
|
|
|
|
const clearInput = useCallback(() => {
|
|
|
|