Reposition dropdown when needed

Adds support for a new attribute to specify a fallback position if the popover doesn't fit on the screen in the default position without getting cut off.