mirror of
https://github.com/discourse/discourse.git
synced 2025-06-07 17:06:01 +08:00
FIX: Autocomplete arrow scroll for mention (#19571)
Follow up to 8820e9418a4b4f89a9cf06a97fe5bcf10724c9a2, 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:
@ -119,28 +119,28 @@ export default function (options) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function scrollAutocomplete() {
|
function scrollAutocomplete() {
|
||||||
if (!fadeoutDiv) {
|
if (!fadeoutDiv && !div) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const fadeoutDivElement = fadeoutDiv[0];
|
const scrollingDivElement = fadeoutDiv?.length > 0 ? fadeoutDiv[0] : div[0];
|
||||||
const selectedElement = getSelectedOptionElement();
|
const selectedElement = getSelectedOptionElement();
|
||||||
const selectedElementTop = selectedElement.offsetTop;
|
const selectedElementTop = selectedElement.offsetTop;
|
||||||
const selectedElementBottom =
|
const selectedElementBottom =
|
||||||
selectedElementTop + selectedElement.clientHeight;
|
selectedElementTop + selectedElement.clientHeight;
|
||||||
|
|
||||||
// the top of the item is above the top of the fadeoutDiv, so scroll UP
|
// the top of the item is above the top of the fadeoutDiv, so scroll UP
|
||||||
if (selectedElementTop <= fadeoutDivElement.scrollTop) {
|
if (selectedElementTop <= scrollingDivElement.scrollTop) {
|
||||||
fadeoutDivElement.scrollTo(0, selectedElementTop);
|
scrollingDivElement.scrollTo(0, selectedElementTop);
|
||||||
|
|
||||||
// the bottom of the item is below the bottom of the div, so scroll DOWN
|
// the bottom of the item is below the bottom of the div, so scroll DOWN
|
||||||
} else if (
|
} else if (
|
||||||
selectedElementBottom >=
|
selectedElementBottom >=
|
||||||
fadeoutDivElement.scrollTop + fadeoutDivElement.clientHeight
|
scrollingDivElement.scrollTop + scrollingDivElement.clientHeight
|
||||||
) {
|
) {
|
||||||
fadeoutDivElement.scrollTo(
|
scrollingDivElement.scrollTo(
|
||||||
0,
|
0,
|
||||||
fadeoutDivElement.scrollTop + selectedElement.clientHeight
|
scrollingDivElement.scrollTop + selectedElement.clientHeight
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user