materialize
materialize copied to clipboard
dropdown: option to disable close on click outside
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
Indeed it would be a very useful feature
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();
});
}, []);