FIX: Autocomplete arrow scroll for mention (#19571)

Follow up to 8820e9418a,
only the hashtag autocomplete has a fadeout scroll, so
we still need to scroll on the original div in some
cases (e.g. mentions)
This commit is contained in:
Martin Brennan 2022-12-22 17:01:51 +10:00 committed by GitHub
parent bef1966ca5
commit 64a7a2aac2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 7 deletions

View File

@ -119,28 +119,28 @@ export default function (options) {
}
function scrollAutocomplete() {
if (!fadeoutDiv) {
if (!fadeoutDiv && !div) {
return;
}
const fadeoutDivElement = fadeoutDiv[0];
const scrollingDivElement = fadeoutDiv?.length > 0 ? fadeoutDiv[0] : div[0];
const selectedElement = getSelectedOptionElement();
const selectedElementTop = selectedElement.offsetTop;
const selectedElementBottom =
selectedElementTop + selectedElement.clientHeight;
// the top of the item is above the top of the fadeoutDiv, so scroll UP
if (selectedElementTop <= fadeoutDivElement.scrollTop) {
fadeoutDivElement.scrollTo(0, selectedElementTop);
if (selectedElementTop <= scrollingDivElement.scrollTop) {
scrollingDivElement.scrollTo(0, selectedElementTop);
// the bottom of the item is below the bottom of the div, so scroll DOWN
} else if (
selectedElementBottom >=
fadeoutDivElement.scrollTop + fadeoutDivElement.clientHeight
scrollingDivElement.scrollTop + scrollingDivElement.clientHeight
) {
fadeoutDivElement.scrollTo(
scrollingDivElement.scrollTo(
0,
fadeoutDivElement.scrollTop + selectedElement.clientHeight
scrollingDivElement.scrollTop + selectedElement.clientHeight
);
}
}