Bug fix scrollbar.

This commit is contained in:
Yaroslavna Gaivoronyuk 2022-02-15 14:33:15 +03:00
parent 84615f1a86
commit 81b9afb3a4

View File

@ -41,6 +41,7 @@ const InputWithChips = ({
const inputRef = useRef(null);
const blockRef = useRef(null);
const scrollbarRef = useRef(null);
const chipsCount = useRef(options.length);
useEffect(() => {
document.addEventListener("keydown", onKeyDown);
@ -55,6 +56,14 @@ const InputWithChips = ({
onChange(selectedChips);
}, [selectedChips]);
useEffect(() => {
const isChipAdd = chips.length > chipsCount.current;
if (scrollbarRef.current && isChipAdd) {
scrollbarRef.current.scrollToBottom();
}
chipsCount.current = chips.length;
}, [chips.length]);
useClickOutside(blockRef, () => {
setSelectedChips([]);
setIsExistedOn(false);
@ -109,10 +118,6 @@ const InputWithChips = ({
setChips([...chips, ...filteredChips]);
setValue("");
if (scrollbarRef.current) {
scrollbarRef.current.scrollToBottom();
}
}
};