Ghost/ghost/admin/app/modifiers/scroll-to.js
Kevin Ansfield 2d6f48093e Renamed {{scroll-to}}'s shouldScroll argument to when
no issue

- `when` makes the modifier a little easier to read for it's typical use-case, eg:
  - `{{scroll-to when=(eq entry.slug this.entry)}}`
  - `{{scroll-to when=(eq this.focusArea "analytics")}}`
2022-11-11 11:53:53 +00:00

14 lines
518 B
JavaScript

import getScrollParent from 'ghost-admin/utils/get-scroll-parent';
import {modifier} from 'ember-modifier';
export default modifier((element, positional, {when = true}) => {
if (when) {
// setTimeout needed to ensure layout has finished and we have accurate positioning
setTimeout(() => {
const scrollParent = getScrollParent(element);
const y = element.offsetTop;
scrollParent.scrollTo({top: y, behavior: 'smooth'});
}, 200);
}
}, {eager: false});