Closing a dropdown after an asynchronous action


Topic: Closing a dropdown after an asynchronous action

Zoe Mason asked 3 weeks ago

An action inside the menu finishes an API request, then sets our open state to false. The menu remains on screen.

How can it be closed programmatically?


Mateusz Lazaru staff answered 3 weeks ago

Please show where your open state is connected to the dropdown and how it changes after the request. If the component only uses that option during initialization, setting the parent value to false will not close an existing menu. Also confirm whether clicking outside the menu closes it normally.

Send a small example using a resolved Promise instead of the API call, together with the dropdown JSX. Please avoid manually removing the menu's DOM nodes or classes: that can leave its internal focus and visibility state inconsistent. We can then trace the state update and recommend a close path that keeps keyboard focus consistent.

https://mdbootstrap.com/docs/react/components/dropdowns/


Please insert min. 20 characters.

FREE CONSULTATION

Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.

Status

Answered

Specification of the issue
  • User: Free
  • Premium support: No
  • Technology: MDB React
  • MDB Version: MDB5 9.0.0
  • Device: Laptop
  • Browser: Firefox
  • OS: macOS
  • Provided sample code: No
  • Provided link: No