Skip to content

Add showValidationMessage() method for validation without focus management #11416

Open
@Hideki-Kobayashi

Description

@Hideki-Kobayashi

What problem are you trying to solve?

Add showValidationMessage() method for validation without focus management

Problem

The current reportValidity() method automatically refocuses the validated element when validation fails, creating poor user experience and accessibility issues.

Issues with current behavior:

  1. Focus trapping: Users cannot navigate away from invalid fields
  2. Poor UX: Interrupts natural form navigation flow
  3. Accessibility problems: Confuses screen reader users

Real-world scenario:

// User types invalid email, then presses Tab
emailInput.addEventListener('blur', () => {
  if (!emailInput.checkValidity()) {
    emailInput.reportValidity(); // Shows error BUT forces focus back
    // User is now trapped - cannot move to next field
  }
});

Proposed Solution

Add a new method showValidationMessage() that displays validation errors without focus management:

// New API - message only, no focus management
element.showValidationMessage();

// Existing API - message + focus (backward compatibility)
element.reportValidity();

Use Case

Real-time validation without focus trap:

field.addEventListener('blur', () => {
  if (!field.checkValidity()) {
    field.showValidationMessage(); // Show error, allow navigation
  }
});

This would significantly improve form validation UX while maintaining backward compatibility.

What solutions exist today?

No response

How would you solve it?

No response

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    a11y-trackerGroup bringing to attention of a11y, or tracked by the a11y Group but not needing response.accessibilityAffects accessibilityaddition/proposalNew features or enhancementsneeds implementer interestMoving the issue forward requires implementers to express interesttopic: forms

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions