Introducing ReUI:Open-source UI components and apps built with React, Next.js and Tailwind CSS
Browse ReUI

Sidebar minimise


Hello within my Laravel App using metronic i can collapse the main sidebar nav and this will collapse okay. When I move to another page or this page is reloaded the navbar defaults back to the maximised display. Could you tell me why this is happening or how to resolve the issue? I would like the navbar to stay minimised when scrolling through the pages If i have set the navbar to minimise.


Text formatting options
Submit

Replies (3)


Hello @ slope game, you can use JavaScript to store the collapsed state of the sidebar in the browser's local storage. When the sidebar is toggled, update the local storage accordingly.

Example JavaScript Code
javascript

Copy
document.addEventListener("DOMContentLoaded", function () {
const sidebar = document.querySelector('.sidebar'); // Adjust selector based on your HTML
const toggleButton = document.querySelector('.sidebar-toggle'); // Adjust selector for your toggle button

// Check localStorage for sidebar state
const isCollapsed = localStorage.getItem('sidebar-collapsed') === 'true';
if (isCollapsed) {
sidebar.classList.add('collapsed'); // Add class to collapse sidebar
}

// Event listener for toggle button
toggleButton.addEventListener('click', function () {
sidebar.classList.toggle('collapsed');
// Store the current state in localStorage
localStorage.setItem('sidebar-collapsed', sidebar.classList.contains('collapsed'));
});
});



The Community-Driven Education is the best to help us and provide great results. The Project Ownership Where it Belongs is amazing and I like that you shared this post for us to know about these ideas. Also from https://www.examstrust.com/ I realize that it is more helpful for us.



Hi

You can set the sidebar minimized by default.

<ul class="px-5 py-0 m-0"> <li class="py-2">Add data-kt-app-sidebar-minimize="on" attribute on the body element. <li class="py-2">Add active class on the toggle element (id=kt_app_sidebar_toggle). <li class="py-2">Set data-kt-toggle-state="active" attribute on the toggle element (id=kt_app_sidebar_toggle).

Thanks


Text formatting options
Submit
Text formatting options
Submit