UNPKG

@stimulus-library/controllers

Version:

A library of useful controllers for Stimulus

19 lines (18 loc) 682 B
import { EphemeralController, scrollToElement } from "@stimulus-library/utilities"; export class ScrollIntoFocusController extends EphemeralController { connect() { requestAnimationFrame(() => { scrollToElement(this.el, { behavior: this.hasBehaviorValue ? this.behaviorValue : "smooth", block: this.hasBlockValue ? this.blockValue : "center", inline: this.hasInlineValue ? this.inlineValue : "center", }).catch(() => this.el.scrollIntoView()); this._cleanupSelf(); }); } } ScrollIntoFocusController.values = { behavior: String, block: String, inline: String, };