Fix logic error in onFocus

Issue #2494