UNPKG

@stimulus-library/controllers

Version:

A library of useful controllers for Stimulus

26 lines (25 loc) 739 B
import { BaseController, getScrollParent, scrollAbsoluteTop } from "@stimulus-library/utilities"; export class ScrollToTopController extends BaseController { get _mode() { return this.hasModeValue ? this.modeValue : "document"; } get _scrollTarget() { let target; if (this._mode == "document") { target = window; } else { target = getScrollParent(this.el); } return target; } async scroll(event) { event === null || event === void 0 ? void 0 : event.preventDefault(); if (this._scrollTarget) { await scrollAbsoluteTop(this._scrollTarget); } } } ScrollToTopController.values = { mode: String, };