mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
UX: Only scrollIntoView
if sidebar items are not already visible (#28372)
When browsing through a sidebar with this feature enabled (i.e. admin, or docs), it's weird to have the scroll jump around when you click an item. This commit adds a check, so that we only `scrollIntoView` for items which are not already in the viewport.
Followup to b7cce1a0dc
This commit is contained in:
parent
f6fadd7129
commit
ede6220347
@ -115,14 +115,22 @@ export default class SectionLink extends Component {
|
|||||||
|
|
||||||
@bind
|
@bind
|
||||||
maybeScrollIntoView(element) {
|
maybeScrollIntoView(element) {
|
||||||
if (this.args.scrollIntoView) {
|
if (!this.args.scrollIntoView) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
schedule("afterRender", () => {
|
schedule("afterRender", () => {
|
||||||
|
const rect = element.getBoundingClientRect();
|
||||||
|
const alreadyVisible = rect.top <= window.innerHeight && rect.bottom >= 0;
|
||||||
|
if (alreadyVisible) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
element.scrollIntoView({
|
element.scrollIntoView({
|
||||||
block: "center",
|
block: "center",
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
{{#if this.shouldDisplay}}
|
{{#if this.shouldDisplay}}
|
||||||
|
Loading…
Reference in New Issue
Block a user