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

Dismiss dropdown menu


Hi,

Is there a preimplemented way to close a dropdown menu on button click?

For example, on metronic react demo 2 notification logs, I'd like to close the menu when clicking on View all. What would be the best way to do this?

Best wishes,
Tamás


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 (10)


import React, { useState } from 'react';

function NotificationDropdown() {
// State to manage the dropdown visibility
const [isDropdownOpen, setIsDropdownOpen] = useState(false);

// Function to toggle dropdown visibility
const toggleDropdown = () => {
setIsDropdownOpen(!isDropdownOpen);
};

// Function to close the dropdown
const closeDropdown = () => {
setIsDropdownOpen(false);
};

return (
<div>
<button onClick={toggleDropdown}>
Notifications
</button>
{isDropdownOpen && (
<div className="dropdown-menu">
<p>Notification 1</p>
<p>Notification 2</p>
<p>Notification 3</p>
<button onClick={closeDropdown}>
View all
</button>
</div>
)}
</div>
);
}

export default NotificationDropdown;

slope game

Dive into the exhilarating world of blackjack with our comprehensive guide. From the basics of gameplay to advanced strategies, we cover everything you need to know to become a master of the game. Whether you're https://www.ardijah.co.nz/payments/mastercard/ a novice player or a seasoned pro, our article provides valuable insights and tips to help you maximize your chances of success at the blackjack table. Join us as we explore the timeless allure of this classic card game.



There's a possibility that it could be related to cached data. To troubleshoot this, could you please try clearing your browser cache and then revisiting the demo URL
Read more: https://devs.keenthemes.com/question/dismiss-dropdown-menu-backrooms game



Hi happy,

Can you try to use the HTML attribute the view all links?

"data-kt-menu-dismiss='true'"

Regards



Hi Sean,

That worked wonderfully. Thanks!
Is there anywhere I can see all the available attributes for future reference?

Best,
Tamás



Hi,

At the moment we do not have a separate components doc for React version, but usage and attribute names should be the same as they are in the HTML version.

You can refer to our HTML version doc.



Thanks Lauris, got it.

Another question I had based on this, is how could one conditionally change some text based on the opened or closed state of an accordion elemenet?



You can add new styles to your component and then modify tag content depending on the accordion state.


.accordion-button.collapsed:before {
content: "more"
}

.accordion-button:before {
content: "less"
}


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