Skip to content

Commit ddfd53d

Browse files
committed
Update scroll container to also scroll vertically when an item is focussed
1 parent 576e76f commit ddfd53d

File tree

1 file changed

+25
-7
lines changed

1 file changed

+25
-7
lines changed

app/components/scroll-container.js

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { action } from '@ember/object';
55
import { debounce } from '@ember/runloop';
66
import { htmlSafe } from '@ember/template';
77
import { tracked } from '@glimmer/tracking';
8+
import { indentItem } from './render-item';
89

910
export default class ScrollContainerComponent extends Component {
1011
attributeBindings = ['style'];
@@ -26,11 +27,13 @@ export default class ScrollContainerComponent extends Component {
2627
}
2728

2829
get scrollTargetStyle() {
29-
let { index, itemHeight } = this;
30+
let { index, itemHeight, previewing, currentItem } = this;
3031

3132
if (index === -1) {
3233
return htmlSafe('display: none;');
3334
} else {
35+
const level = previewing?.level ?? currentItem?.level ?? 0;
36+
const left = indentItem(level) + 10;
3437
const height = itemHeight ?? 0;
3538

3639
return htmlSafe(`
@@ -39,8 +42,8 @@ export default class ScrollContainerComponent extends Component {
3942
height: ${height}px;
4043
margin: 0px;
4144
padding: 0px;
42-
left: 0px;
4345
top: ${index * height}px;
46+
left: ${left}px;
4447
z-index: -9999;
4548
pointer-events: none;
4649
`);
@@ -98,10 +101,25 @@ export default class ScrollContainerComponent extends Component {
98101
}
99102

100103
function needsScroll(container, target) {
101-
if (!container || !target) return false;
104+
if (!container || !target) {
105+
return false;
106+
}
102107

103-
let { top: containerTop, bottom: containerBottom } =
104-
container.getBoundingClientRect();
105-
let { top: targetTop, bottom: targetBottom } = target.getBoundingClientRect();
106-
return targetTop < containerTop || targetBottom > containerBottom;
108+
let {
109+
top: containerTop,
110+
bottom: containerBottom,
111+
left: containerLeft,
112+
} = container.getBoundingClientRect();
113+
114+
let {
115+
top: targetTop,
116+
bottom: targetBottom,
117+
left: targetLeft,
118+
} = target.getBoundingClientRect();
119+
120+
return (
121+
targetTop < containerTop ||
122+
targetBottom > containerBottom ||
123+
targetLeft > containerLeft
124+
);
107125
}

0 commit comments

Comments
 (0)