-
Notifications
You must be signed in to change notification settings - Fork 4k
Description
From the Focusing chapter:
Methods elem.focus() and elem.blur() set/unset the focus on the element.
For instance, let’s make the visitor unable to leave the input if the value is invalid:
I think the tutorial should mention that forcefully returning focus to an element is an anti-pattern.
The user may know the value they entered is invalid, but want to complete the rest of the form first. The user may not have the relevant information immediately at hand.
Worse, in cases where validation depends on the value of several forms, trapping user focus may create a catch 22 where user needs to edit form B to validate form A, but user can't edit form B until form A is valid.
These are all use-cases I've personally encountered, by the way. Unfortunately, accessibility guidelines don't really cover this pattern; but what they do recommend is making errors visible; not stopping any possible progress until the error is fixed.
Limiting all user interaction until a single problem is fixed is user-hostile and condescending, and IMHO should be avoided.