UI: apply margin only if the menu has content (PR #9857)

GitHub