DEV: Add correct-scroll-position behavior transformer (#31486)

Add `correct-scroll-position` behavior transformer
This commit is contained in:
Isaac Janzen
2025-02-25 11:16:10 -06:00
committed by GitHub
parent f498c3b3e8
commit 74374e21a8
2 changed files with 14 additions and 13 deletions

View File

@ -49,17 +49,17 @@ function correctScrollPosition() {
// This pushes the fixed element offscreen
// Here we detect when the composer's top position is above the window's
// current scroll offset and correct it
later(() => {
const el = document.querySelector("#reply-control");
const rect = el.getBoundingClientRect();
if (rect.top < -1) {
const scrollAmount = window.scrollY + rect.top;
window.scrollTo({
top: scrollAmount,
behavior: "instant",
});
}
}, 150);
applyBehaviorTransformer("composer-position:correct-scroll-position", () => {
later(() => {
const el = document.querySelector("#reply-control");
const rect = el.getBoundingClientRect();
if (rect.top < -1) {
const scrollAmount = window.scrollY + rect.top;
window.scrollTo({
top: scrollAmount,
behavior: "instant",
});
}
}, 150);
});
}

View File

@ -1,5 +1,6 @@
export const BEHAVIOR_TRANSFORMERS = Object.freeze([
// use only lowercase names
"composer-position:correct-scroll-position",
"composer-position:editor-touch-move",
"discovery-topic-list-load-more",
"full-page-search-load-more",