materialize icon indicating copy to clipboard operation
materialize copied to clipboard

dropdown: option to disable close on click outside

Open ganeshkantu opened this issue 7 years ago • 2 comments

Description

When programmatically opening and closing a dropdown (using open() and close() methods), it would good to have an option to disable close on click outside. Currently dropdown is closed if user clicks outside.

Repro Steps

Open dropdown using $('#dropdown').open() Click outside the dropdown area and the dropdown closes

Screenshots / Codepen

NA

ganeshkantu avatar May 23 '17 19:05 ganeshkantu

Indeed it would be a very useful feature

przmak avatar Sep 27 '19 13:09 przmak

it was opposite for me i.e. the dropdown doesnt close when a user clicks outside.. here is how i did it...(reactjs)

useEffect(() => {
    M.Dropdown.init(dropdownRef.current);
    document.body.addEventListener("click", (event) => {
      if (dropdownRef.current.contains(event.target)) {
        return;
      }
      const instance = M.Dropdown.getInstance(dropdownRef.current);
      instance.close();
    });
  }, []);

shameekagarwal avatar Nov 16 '20 17:11 shameekagarwal