Skip to content

Commit e1bd150

Browse files
authored
Fix menu scroll position (#133)
* Fix menu scroll position * Move js to stimulus controller
1 parent 0decfa4 commit e1bd150

File tree

5 files changed

+25
-8
lines changed

5 files changed

+25
-8
lines changed

app/javascript/controllers/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,6 @@ application.register("color-theme", ColorThemeController)
99

1010
import LottieController from "./lottie_controller"
1111
application.register("lottie", LottieController)
12+
13+
import SidebarMenuController from "./sidebar_menu_controller"
14+
application.register("sidebar-menu", SidebarMenuController)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { Controller } from "@hotwired/stimulus"
2+
3+
// Connects to data-controller="sidebar-menu"
4+
export default class extends Controller {
5+
connect() {
6+
window.addEventListener("turbo:before-visit", () => {
7+
localStorage.setItem("menuScrollPositon", this.element.scrollTop);
8+
});
9+
10+
window.addEventListener("turbo:load", () => {
11+
this.element.scrollTop = localStorage.getItem("menuScrollPositon") || 0;
12+
});
13+
}
14+
}

app/views/components/shared/sidebar.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ class Shared::Sidebar < ApplicationComponent
44
def view_template
55
aside(class: "fixed top-14 z-30 -ml-2 hidden h-[calc(100vh-3.5rem)] w-full shrink-0 md:sticky md:block") do
66
div(class: "relative overflow-hidden h-full py-6 pl-8 pr-6 lg:py-8", style: "position:relative;--radix-scroll-area-corner-width:0px;--radix-scroll-area-corner-height:0px") do
7-
div(class: "h-full w-full rounded-[inherit]", style: "overflow: hidden scroll;") do
7+
div(class: "h-full w-full rounded-[inherit]", style: "overflow: hidden scroll;", data_controller: "sidebar-menu") do
88
render Shared::Menu.new
99
end
1010
end

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"private": "true",
44
"dependencies": {
55
"@hotwired/stimulus": "3.2.2",
6-
"@hotwired/turbo-rails": "8.0.5",
6+
"@hotwired/turbo-rails": "8.0.12",
77
"autoprefixer": "10.4.19",
88
"chart.js": "4.4.3",
99
"class-variance-authority": "0.7.0",

yarn.lock

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -159,15 +159,15 @@
159159
resolved "https://registry.yarnpkg.com/@hotwired/stimulus/-/stimulus-3.2.2.tgz#071aab59c600fed95b97939e605ff261a4251608"
160160
integrity sha512-eGeIqNOQpXoPAIP7tC1+1Yc1yl1xnwYqg+3mzqxyrbE5pg5YFBZcA6YoTiByJB6DKAEsiWtl6tjTJS4IYtbB7A==
161161

162-
"@hotwired/[email protected].5":
163-
version "8.0.5"
164-
resolved "https://registry.yarnpkg.com/@hotwired/turbo-rails/-/turbo-rails-8.0.5.tgz#18c2f0e4f7f952307650308590edf5eb9544b0d3"
165-
integrity sha512-1A9G9u28IRAl0C57z8Ka3AhNPyJdwfOrbjr+ABZk2ZEUw2QO7cJ0pgs77asUj2E/tzn1PgrxrSVu24W+1Q5uBA==
162+
"@hotwired/[email protected].12":
163+
version "8.0.12"
164+
resolved "https://registry.yarnpkg.com/@hotwired/turbo-rails/-/turbo-rails-8.0.12.tgz#6f1a2661122c0a2bf717f3bc68b5106638798c89"
165+
integrity sha512-ZXwu9ez+Gd4RQNeHIitqOQgi/LyqY8J4JqsUN0nnYiZDBRq7IreeFdMbz29VdJpIsmYqwooE4cFzPU7QvJkQkA==
166166
dependencies:
167-
"@hotwired/turbo" "^8.0.5"
167+
"@hotwired/turbo" "^8.0.12"
168168
"@rails/actioncable" "^7.0"
169169

170-
"@hotwired/turbo@^8.0.5":
170+
"@hotwired/turbo@^8.0.12":
171171
version "8.0.12"
172172
resolved "https://registry.yarnpkg.com/@hotwired/turbo/-/turbo-8.0.12.tgz#50aa8345d7f62402680c6d2d9814660761837001"
173173
integrity sha512-l3BiQRkD7qrnQv6ms6sqPLczvwbQpXt5iAVwjDvX0iumrz6yEonQkNAzNjeDX25/OJMFDTxpHjkJZHGpM9ikWw==

0 commit comments

Comments
 (0)