Skip to content

Anti-pattern in the focusing chapter #3032

@PoignardAzur

Description

@PoignardAzur

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions