Using stopPropagation() to simplify the focus-switching logic.