Skip to content
This repository has been archived by the owner on Nov 2, 2021. It is now read-only.

Fix: distorted search bar placeholder #2327

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 14 additions & 3 deletions src/components/Search.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ function Search() {
const [searchValue, setSearchValue] = useState('');
const [expand, setExpand] = useState(false);
const [results, setResults] = useState([]);
const [timeoutId, setTimeoutId] = useState([]);
const searchInput = useRef(null);
const {t} = useTranslation();

Expand Down Expand Up @@ -179,9 +180,10 @@ function Search() {
target.classList.remove('disappear');
target.textContent = placeholder + text[cursorPosition];
if (cursorPosition < text.length - 1) {
setTimeout(function () {
const id = setTimeout(function () {
fillPlaceholder(target, index, cursorPosition + 1, callback);
}, 200);
setTimeoutId((prev) => [...prev, id]);
return true;
}
callback();
Expand All @@ -193,10 +195,11 @@ function Search() {
const placeholder = target.textContent;
target.classList.add('disappear');
if (placeholder.length > 0) {
setTimeout(function () {
const id = setTimeout(function () {
target.textContent = '';
clearPlaceholder(target, callback);
}, 1000);
setTimeoutId((prev) => [...prev, id]);
return true;
}
callback();
Expand All @@ -210,11 +213,12 @@ function Search() {
}

fillPlaceholder(target, index, 0, function () {
setTimeout(function () {
const id = setTimeout(function () {
clearPlaceholder(target, function () {
loopThroughSuggestions(target, (index + 1) % suggestions.length);
});
}, 2000);
setTimeoutId((prev) => [...prev, id]);
});
},
[clearPlaceholder, expand, fillPlaceholder]
Expand All @@ -227,9 +231,12 @@ function Search() {
)[0];

if (targetInput) {
targetInput.textContent = '';
clearAllTimeouts(timeoutId);
loopThroughSuggestions(targetInput, 0);
}
}
// eslint-disable-next-line
}, [expand, loopThroughSuggestions]);

const trail = useMemo(() => {
Expand Down Expand Up @@ -360,6 +367,10 @@ function Search() {
);
}

const clearAllTimeouts = (timeouts) => {
timeouts.forEach((id) => clearTimeout(id));
};

const isEqual = () => {
return true;
};
Expand Down