Get 2024 Templates Mega Bundle!$1000 worth of 19 Bootstrap HTML, Vue & React Templates + 3 Vector Sets for just $99
Get for 99$

Issue opening a dropdown with - data-kt-menu-trigger='click'


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.


Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(

Replies (5)


import React, {useRef, useEffect} from 'react'
import {useLocation} from 'react-router'
import clsx from 'clsx'
import {AsideMenuMain} from './AsideMenuMain'
import {
DrawerComponent,
MenuComponent,
ScrollComponent,
ToggleComponent,
} from '../../../assets/ts/components'

type Props = {
asideMenuCSSClasses: string[]
}

const AsideMenu: React.FC<Props> = ({asideMenuCSSClasses}) => {
const scrollRef = useRef<HTMLDivElement | null>(null)
const {pathname} = useLocation()

useEffect(() => {
setTimeout(() => {
MenuComponent.reinitialization()
DrawerComponent.reinitialization()
ToggleComponent.reinitialization()
ScrollComponent.reinitialization()
if (scrollRef.current) {
scrollRef.current.scrollTop = 0
}
}, 100)
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [pathname])

return (
<div
id='kt_aside_menu_wrapper'
ref={scrollRef}
className='hover-scroll-overlay-y my-5 my-lg-5'
data-kt-scroll='true'
data-kt-scroll-activate='{default: false, lg: true}'
data-kt-scroll-height='auto'
data-kt-scroll-dependencies='#kt_aside_logo, #kt_aside_footer'
data-kt-scroll-wrappers='#kt_aside_menu'
data-kt-scroll-offset='0'
>
<div
id='#kt_aside_menu'
data-kt-menu='true'
className={clsx(
'menu menu-column menu-title-gray-800 menu-state-title-primary menu-state-icon-primary menu-state-bullet-primary menu-arrow-gray-500',
asideMenuCSSClasses.join(' ')
)}
>
<AsideMenuMain />
</div>
</div>
)
}

export {AsideMenu}


I used below format still I'm facing issue on this button. drop down not comming.



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>

So basically, a dropdown containing two items(each of them being a popup) should open up while the button is clicked.



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.



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


Your Support Matters!

We will highly appreciate your Metronic Review on Themeforest.
Please go to Themeforest Downloads page, select Metronic & leave your feedback.
Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(
Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(