Skip to content

Commit

Permalink
Allow frames to scroll smoothly into view (hotwired#607)
Browse files Browse the repository at this point in the history
  • Loading branch information
npezza93 committed Jul 15, 2022
1 parent 2d5cdda commit 39fe418
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/core/frames/frame_renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ export class FrameRenderer extends Renderer<FrameElement> {
if (this.currentElement.autoscroll || this.newElement.autoscroll) {
const element = this.currentElement.firstElementChild
const block = readScrollLogicalPosition(this.currentElement.getAttribute("data-autoscroll-block"), "end")
const behavior = readScrollBehavior(this.currentElement.getAttribute("data-autoscroll-behavior"), "auto")

if (element) {
element.scrollIntoView({ block })
element.scrollIntoView({ block, behavior })
return true
}
}
Expand All @@ -64,3 +65,11 @@ function readScrollLogicalPosition(value: string | null, defaultValue: ScrollLog
return defaultValue
}
}

function readScrollBehavior(value: string | null, defaultValue: ScrollBehavior): ScrollBehavior {
if (value == "auto" || value == "smooth") {
return value
} else {
return defaultValue
}
}

0 comments on commit 39fe418

Please sign in to comment.