Hi,
I’m using the Metronic 8 Demo4 React version. I’m facing an issue when I tried to add data-kt-menu-trigger=’click’ on a button which upon clicking, opens up a dropdown similar to Quick Actions. The issue is- it sometimes opens up, and sometimes doesn’t. Could I please get a solution to this?
Thanks.
Hi,
Could you investigate when it starts not opening? If it's after changing routes, then you can implement the next solution:
In your component add const location = useLocation() // import from react-router
useEffect(() => { // import from react
MenuComponent.reinitialization() // import from assets/ts/components
}, [location])
Regards,
Keenthemes support
It doesn't involve changing routes. Also, dropdown not opening is happening randomly.
Here is the code that I'm working on-
<div className="card-toolbar">
{/* begin::Menu */}
<button type="button" className="btn btn-sm btn-light-primary" data-kt-menu-trigger="click" data-kt-menu-placement="bottom-end" data-kt-menu-flip="top-end">
<KTSVG path="/media/icons/duotune/arrows/arr075.svg" className="svg-icon-3"/>View Popup
</button>
{/* begin::Menu 2 */}
<div className="menu menu-sub menu-sub-dropdown menu-column menu-rounded menu-gray-600 menu-state-bg-light-primary fw-bold w-200px" data-kt-menu="true">
<div className="menu-item px-3">
<div className="menu-content fs-6 text-dark fw-bolder px-3 py-4">List of Popup"s</div>
</div>
<div className="separator mb-3 opacity-75"></div>
<div className="menu-item px-3">
<a href="#" className="menu-link px-3" data-bs-toggle="modal" data-bs-target="#kt_modal_popup_one">
Popup 1
</a>
</div>
<div className="menu-item px-3">
<a href="#" className="menu-link px-3" data-bs-toggle="modal" data-bs-target="#kt_modal_popup_two">
Popup 2
</a>
</div>
<div className="separator mt-3 opacity-75"></div>
</div>
{/* end::Menu 2 */}
{/* end::Menu */}
</div>
Try to debug your comnent and check for which props/states React re-renders your component and put them into useEffect
dependencies.
Also you can wrap MenuComponent.reinitialization()
with setTimeout (with 100 ms)
to be sure that your html is already in the DOM.
Regards,
Keenthemes support
Okay, thankyou for your help.