Avoid positioning the menu outside of the window