Get 2024 Templates Mega Bundle!14 Bootstrap, Vue & React Templates + 3 Vector Sets
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 (4)


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.

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.


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  :(