فینورا پرو - سامانه جامع حسابداری و صدور فاکتور
fix(ux): persist sidebar collapse, update accessible state and retain nav names when collapsed
davoodmehraban89 committed
Oct 30, 2026 at 23:19 UTC
f45f9a65ce1e70fdcff3e7d8c45554aa7fffa1ed
1 file changed
+30
-4
src/main.js
+30
-4
@@ -52,6 +52,23 @@ const ROUTES = [
52
{ name: 'settings', title: 'تنظیمات', header: 'تنظیمات', view: SettingsView }
53
];
54
55
+const SIDEBAR_COLLAPSED_KEY = 'finora_pro_sidebar_collapsed';
56
+
57
+function toggleSidebar() {
58
+ const sidebar = document.getElementById('sidebar');
59
+ const main = document.getElementById('main');
60
+ const button = document.getElementById('sidebarToggleBtn');
61
+ if (!sidebar || !main || !button) return false;
62
+ const collapsed = !sidebar.classList.contains('collapsed');
63
+ sidebar.classList.toggle('collapsed', collapsed);
64
+ main.classList.toggle('sidebar-collapsed', collapsed);
65
+ button.setAttribute('aria-expanded', String(!collapsed));
66
+ button.setAttribute('aria-label', collapsed ? 'باز کردن منوی اصلی' : 'بستن منوی اصلی');
67
+ localStorage.setItem(SIDEBAR_COLLAPSED_KEY, String(collapsed));
68
+ return collapsed;
69
+}
70
+FINORA.Layout = { toggleSidebar };
71
+
72
const DEFAULT_ROUTE = 'dashboard';
73
const LAST_ROUTE_KEY = 'finora_pro_last_route';
74
@@ -104,16 +121,25 @@ async function updateStats() {
121
}
122
123
function setupSidebar() {
107
- document.querySelectorAll('[data-page]').forEach(a => {
124
+ document.querySelectorAll('#sidebarMenu [data-page]').forEach(a => {
125
+ const label = a.querySelector('.label')?.textContent?.trim();
126
+ if (label) {
127
+ a.setAttribute('aria-label', label);
128
+ a.setAttribute('title', label);
129
+ }
130
a.addEventListener('click', e => {
131
e.preventDefault();
132
Router.go(a.dataset.page);
133
});
134
});
135
114
- if (localStorage.getItem('finora_pro_sidebar_collapsed') === 'true') {
115
- document.getElementById('sidebar').classList.add('collapsed');
116
- document.getElementById('main').classList.add('sidebar-collapsed');
136
+ const collapsed = localStorage.getItem(SIDEBAR_COLLAPSED_KEY) === 'true';
137
+ document.getElementById('sidebar').classList.toggle('collapsed', collapsed);
138
+ document.getElementById('main').classList.toggle('sidebar-collapsed', collapsed);
139
+ const button = document.getElementById('sidebarToggleBtn');
140
+ if (button) {
141
+ button.setAttribute('aria-expanded', String(!collapsed));
142
+ button.setAttribute('aria-label', collapsed ? 'باز کردن منوی اصلی' : 'بستن منوی اصلی');
143
}
144
}
145