feat: scroll timeline to today's date on first load
closes #869b9vhrj
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
import { Controller } from '@hotwired/stimulus'
|
||||
|
||||
export default class extends Controller {
|
||||
static targets = [ 'today' ]
|
||||
|
||||
connect() {
|
||||
if (false === this.hasTodayTarget) {
|
||||
return
|
||||
}
|
||||
|
||||
requestAnimationFrame(() => {
|
||||
const containerRect = this.element.getBoundingClientRect()
|
||||
const todayRect = this.todayTarget.getBoundingClientRect()
|
||||
|
||||
const scrollLeft = todayRect.left - containerRect.left + this.element.scrollLeft
|
||||
const centered = scrollLeft - (this.element.clientWidth / 2) + (todayRect.width / 2)
|
||||
const maxScrollLeft = this.element.scrollWidth - this.element.clientWidth
|
||||
|
||||
this.element.scrollLeft = Math.min(Math.max(0, centered), maxScrollLeft)
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user