You can use the mui ClickAwayListener API.
https://mui.com/material-ui/api/click-away-listener/?srsltid=AfmBOoqzwKvmi5geXh7TQ5hcee0xj3wqVRICSe4nwpWnjx4qgBfg4MZs