-
-
Notifications
You must be signed in to change notification settings - Fork 18.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] Sidebar not working correctly with React.js on Vite #5597
Comments
any progress or work around yo handle this problem??? |
@MikhaelMounay after a long research and base on the issue you tagged import $ from 'jquery'; this is my AdminLTE setup import 'admin-lte/dist/css/adminlte.css';
import 'admin-lte/plugins/fontawesome-free/css/all.css';
import 'admin-lte'; this is how my import { BrowserRouter as Router } from 'react-router-dom';
import App from './App';
import { hydrateRoot } from 'react-dom/client';
import { StrictMode } from 'react';
import $ from 'jquery';
import 'admin-lte/dist/css/adminlte.css';
import 'admin-lte/plugins/fontawesome-free/css/all.css';
import 'admin-lte/dist/js/adminlte.js';
const rootElement = document.getElementById('root');
if (rootElement) {
window.jQuery = $;
hydrateRoot(
rootElement,
<StrictMode>
<Router>
<App />
</Router>
</StrictMode>,
);
} both jQuery and AdminLTE are imported in my and this is my declare global {
interface Window {
jQuery: JQueryStatic;
}
interface JQuery {
Treeview(option: string): JQuery;
}
} and inside your component, using the useEffect(() => {
const initializeTreeWidgets = () => {
if (window.jQuery) {
const $ = window.jQuery;
// Initialize the tree widget (ensure Tree is callable)
const trees = $('[data-widget="treeview"]:not(.initialized)');
if (trees.length > 0) {
trees.each(function () {
try {
// Initialize the widget (AdminLTE Treeview)
$(this).Treeview('init');
// Mark it as initialized by adding a class or data attribute
$(this).addClass('initialized');
console.log('Initialized Treeview:', this);
} catch (error) {
console.log('Error initializing Treeview widget:', error);
}
});
}
}
};
initializeTreeWidgets();
return () => {
};
}, []); // Empty dependency array ensures this effect runs once on mount |
This is a very similar bug discussed in this issue.
#1570
I working on a web application with AdminLTE 3 and React.js 18 on Vite 5.
The sidebar works fine without adding any code on Google Chrome and Brave. However, this error persists on Microsoft Edge (Chromium based) where the buttons of the tree view are not working.
If I use this snippet,
MS Edge works fine, but Google Chrome & Brave don't work as expected where the menus expand only but don't collapse.
Anyone has an idea ?!
Thank you in advance!
The text was updated successfully, but these errors were encountered: