Introducing ReUI:Open-source UI components and apps built with React, Next.js and Tailwind CSS
Browse ReUI

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


Itu pertanyaan yang menarik! Bekerja dengan menu drop-down di UI/UX adalah seperti menyiapkan mekanisme yang tepat: jika ada sesuatu yang salah, seluruh sistem akan mengalami kerusakan. Dalam pemrograman, Anda sering kali harus memikirkan logika interaksi dengan cara yang sama seperti para insinyur memikirkan proses fisik. Ngomong-ngomong, ketika saya bekerja untuk mengoptimalkan antarmuka, saya menyadari bahwa banyak solusi yang bisa ditransfer dari dunia nyata.

Contohnya, cara kerja mesin cetak hidrolik https://hydromarket.co.id/katalog-produk/hidrolik/hidrolik-lainnya/hydraulic-press sangat mirip dengan cara kita mengontrol elemen UI. Alat ini memungkinkan Anda mengompresi dan mengontrol tekanan secara presisi, dan pada UI, pada dasarnya, kita melakukan hal yang sama - mengontrol perilaku komponen dengan menetapkan parameter dan batasan yang jelas. Jika sebuah menu tidak bersembunyi dengan benar, kita harus memikirkan “kekuatan” (penekanan, peristiwa) apa yang mempengaruhinya dan di mana kita perlu menyesuaikan “tekanan” (logika kode).

Jadi, jika Anda menghadapi masalah UI, terkadang ada baiknya untuk melihat prinsip-prinsip mekanis - prinsip-prinsip ini memberikan ide yang tidak terduga untuk memecahkan masalah yang murni digital!



It's inspiring to see aspiring developers come together to share ideas and techniques. Simple games can often be the most engaging, providing a great platform for learning and growth. If you're looking for inspiration, consider checking out the Fairplay app in India, which showcases how straightforward concepts can lead to successful projects. It’s fantastic to see the gaming community thrive and support one another in bringing unique ideas to life. Keep up the great work, everyone—exciting times are ahead!


Deleted comment

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