Skip to content

A platform for community discussion. Free, open, simple.

UX: Only `scrollIntoView` if sidebar items are not already visible (#28372)

David Taylorede622034789
diff --git a/app/assets/javascripts/discourse/app/components/sidebar/section-link.gjs b/app/assets/javascripts/discourse/app/components/sidebar/section-link.gjs
index 6b748fe2350..f8746eff7c9 100644
--- a/app/assets/javascripts/discourse/app/components/sidebar/section-link.gjs
+++ b/app/assets/javascripts/discourse/app/components/sidebar/section-link.gjs
@@ -115,13 +115,21 @@ export default class SectionLink extends Component {
@bind
maybeScrollIntoView(element) {
- if (this.args.scrollIntoView) {
- schedule("afterRender", () => {
- element.scrollIntoView({
- block: "center",
- });
- });
+ if (!this.args.scrollIntoView) {
+ return;
}
+
+ schedule("afterRender", () => {
+ const rect = element.getBoundingClientRect();
+ const alreadyVisible = rect.top <= window.innerHeight && rect.bottom >= 0;
+ if (alreadyVisible) {
+ return;
+ }
+
+ element.scrollIntoView({
+ block: "center",
+ });
+ });
}
<template>