Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent materializecss dropdown to close when clicking inside it

I am using Materialize.css for current project, and I have dropdown with some input forms inside it.

Dropdown has option to close by:

  • clicking outside of .dropdown-content
  • clicking inside of .dropdown-content
  • clicking on .dropdown-button

What I need is to not close when clicking inside of it, because i need to be able to fill in input forms and other actions.

Here is simple example

like image 720
Plavookac Avatar asked Feb 06 '23 00:02

Plavookac


1 Answers

Quick solution would be to stopPropagation on click on content wrapper.

$('.dropdown-button + .dropdown-content').on('click', function(event) {
  event.stopPropagation();
});

I would avoid using 'dropdown' for this particular use-case. But if you want to stick to it just apply the snippet above.

like image 164
Develoger Avatar answered Feb 08 '23 17:02

Develoger